band_position = min(1.0, max(-1.0, band_position)) # Convert the difference between the band and goal positions into a colour hue position_diff = min(abs(band_position - goal_position), 1.0) hue = map(position_diff, 0.0, 1.0, VELOCITY_MODE_GOAL_HUE, VELOCITY_MODE_EDGE_HUE) # Convert the band and goal positions to positions on the LED strip strip_band_position = map(band_position, -1.0, 1.0, 0.0, float(NUM_LEDS)) strip_goal_position = map(goal_position, -1.0, 1.0, 0.0, float(NUM_LEDS)) # Draw the band and goal colour_band(strip_band_position, BAND_PIXEL_WIDTH, strip_goal_position, GOAL_PIXEL_WIDTH, hue) sw_pressed = user_sw.read() a_pressed = button_a.read() b_pressed = button_b.read() if b_pressed: game_mode = not game_mode if sw_pressed: invert = not invert if mode == ANGLE: if game_mode: led.set_rgb(255, 255, 0) else: led.set_rgb(0, 255, 0) if a_pressed:
button_a = Button(plasma2040.BUTTON_A) button_b = Button(plasma2040.BUTTON_B) led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B) sense = Analog(plasma2040.CURRENT_SENSE, plasma2040.ADC_GAIN, plasma2040.SHUNT_RESISTOR) # Start updating the LED strip led_strip.start() speed = DEFAULT_SPEED offset = 0.0 count = 0 # Make rainbows while True: sw = user_sw.read() a = button_a.read() b = button_b.read() if sw: speed = DEFAULT_SPEED else: if a: speed -= 1 if b: speed += 1 speed = min(255, max(1, speed)) offset += float(speed) / 2000.0
import time # Import plasma2040 from plasma import plasma2040 # Import helpers for RGB LEDs and Buttons from pimoroni import RGBLED, Button led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B) led.set_rgb(0, 0, 0) user_sw = Button(plasma2040.USER_SW) button_a = Button(plasma2040.BUTTON_A) button_b = Button(plasma2040.BUTTON_B) while True: if user_sw.read(): print("Pressed User SW - {}".format(time.ticks_ms())) led.set_rgb(255, 0, 0) if button_a.read(): print("Pressed A - {}".format(time.ticks_ms())) led.set_rgb(0, 255, 0) if button_b.read(): print("Pressed B - {}".format(time.ticks_ms())) led.set_rgb(0, 0, 255)
from plasma import plasma2040 from pimoroni import RGBLED, Button NUM_LEDS = 50 led = RGBLED(plasma2040.LED_R, plasma2040.LED_G, plasma2040.LED_B) led.set_rgb(0, 0, 0) button_a = Button(plasma2040.BUTTON_A) button_b = Button(plasma2040.BUTTON_B) button_boot = Button(plasma2040.USER_SW) led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma2040.DAT) led_strip.start() while True: if button_a.read(): for i in range(NUM_LEDS): led_strip.set_rgb(i, 255, 0, 0) led.set_rgb(255, 0, 0) if button_b.read(): for i in range(NUM_LEDS): led_strip.set_rgb(i, 0, 255, 0) led.set_rgb(0, 255, 0) if button_boot.read(): for i in range(NUM_LEDS): led_strip.set_rgb(i, 0, 0, 0) led.set_rgb(0, 0, 0)
HUMIDITY_HUE_END) elif mode == TEMPERATURE: t = map(temperature, TEMPERATURE_C_MIN, TEMPERATURE_C_MAX, 0.0, 1.0) colour_gauge(t, 0, NUM_LEDS, TEMPERATURE_HUE_START, TEMPERATURE_HUE_END) elif mode == PRESSURE: t = map(pressure, PRESSURE_PA_MIN, PRESSURE_PA_MAX, 0.0, 1.0) colour_gauge(t, 0, NUM_LEDS, PRESSURE_HUE_START, PRESSURE_HUE_END) elif mode == HUMIDITY: t = map(humidity, HUMIDITY_MIN, HUMIDITY_MAX, 0.0, 1.0) colour_gauge(t, 0, NUM_LEDS, HUMIDITY_HUE_START, HUMIDITY_HUE_END) a_pressed = button_a.read() b_pressed = button_b.read() if mode == ALL: led.set_rgb(127, 127, 127) if a_pressed: mode = TEMPERATURE elif b_pressed: mode = HUMIDITY elif mode == TEMPERATURE: led.set_rgb(255, 0, 255) if a_pressed: mode = PRESSURE elif b_pressed: mode = ALL