2021-07-21 14:51:37 +01:00
|
|
|
import plasma
|
|
|
|
import time
|
|
|
|
|
2021-08-18 12:18:25 +01:00
|
|
|
# Import helpers for RGB LEDs, Buttons, and Analog
|
|
|
|
from pimoroni import RGBLED, Button, Analog
|
2021-08-17 13:25:46 +01:00
|
|
|
|
2021-08-18 12:18:25 +01:00
|
|
|
# Press "B" to speed up the LED cycling effect.
|
|
|
|
# Press "A" to slow it down again.
|
|
|
|
# Press "Boot" to reset the speed back to default.
|
|
|
|
|
|
|
|
# Set how many LEDs you have
|
2021-07-21 14:51:37 +01:00
|
|
|
NUM_LEDS = 30
|
2021-08-18 12:18:25 +01:00
|
|
|
|
|
|
|
# The speed that the LEDs will start cycling at
|
|
|
|
DEFAULT_SPEED = 10
|
|
|
|
|
|
|
|
# How many times the LEDs will be updated per second
|
2021-08-17 13:25:46 +01:00
|
|
|
UPDATES = 60
|
2021-07-21 14:51:37 +01:00
|
|
|
|
2021-08-18 12:18:25 +01:00
|
|
|
|
|
|
|
# Pick *one* LED type by uncommenting the relevant line below:
|
|
|
|
|
2021-07-21 14:51:37 +01:00
|
|
|
# APA102 / DotStar™ LEDs
|
2021-08-18 12:18:25 +01:00
|
|
|
# led_strip = plasma.APA102(NUM_LEDS, 0, 0, plasma.PIN_DAT, plasma.PIN_CLK)
|
|
|
|
|
|
|
|
# WS2812 / NeoPixel™ LEDs
|
|
|
|
led_strip = plasma.WS2812(NUM_LEDS, 0, 0, plasma.PIN_DAT)
|
2021-08-17 13:25:46 +01:00
|
|
|
|
2021-08-18 12:18:25 +01:00
|
|
|
user_sw = Button(plasma.PIN_USER_SW)
|
|
|
|
button_a = Button(plasma.PIN_BUTTON_A)
|
|
|
|
button_b = Button(plasma.PIN_BUTTON_B)
|
|
|
|
led = RGBLED(plasma.PIN_LED_R, plasma.PIN_LED_G, plasma.PIN_LED_B)
|
2021-08-17 13:25:46 +01:00
|
|
|
sense = Analog(plasma.PIN_CURRENT_SENSE, plasma.ADC_GAIN, plasma.SHUNT_RESISTOR)
|
2021-07-21 14:51:37 +01:00
|
|
|
|
|
|
|
# Start updating the LED strip
|
|
|
|
led_strip.start()
|
|
|
|
|
2021-08-18 12:18:25 +01:00
|
|
|
speed = DEFAULT_SPEED
|
|
|
|
offset = 0.0
|
|
|
|
|
2021-08-17 13:25:46 +01:00
|
|
|
count = 0
|
2021-07-21 14:51:37 +01:00
|
|
|
# Make rainbows
|
|
|
|
while True:
|
2021-08-18 12:18:25 +01:00
|
|
|
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
|
|
|
|
|
2021-07-21 14:51:37 +01:00
|
|
|
for i in range(NUM_LEDS):
|
2021-08-18 12:18:25 +01:00
|
|
|
hue = float(i) / NUM_LEDS
|
|
|
|
led_strip.set_hsv(i, hue + offset, 1.0, 1.0)
|
|
|
|
|
|
|
|
led.set_rgb(speed, 0, 255 - speed)
|
2021-08-17 13:25:46 +01:00
|
|
|
|
|
|
|
count += 1
|
|
|
|
if count >= UPDATES:
|
|
|
|
# Display the current value once every second
|
|
|
|
print("Current =", sense.read_current(), "A")
|
|
|
|
count = 0
|
2021-08-17 13:43:42 +01:00
|
|
|
|
2021-08-17 13:25:46 +01:00
|
|
|
time.sleep(1.0 / UPDATES)
|