kopia lustrzana https://github.com/pimoroni/pimoroni-pico
add spooky rainbows for @guru
rodzic
d7f85c1160
commit
e986832414
|
@ -33,9 +33,34 @@ def status_handler(mode, status, ip):
|
|||
print('Connection successful!')
|
||||
else:
|
||||
print('Connection failed!')
|
||||
# light up red if connection fails
|
||||
for i in range(NUM_LEDS):
|
||||
led_strip.set_rgb(i, 255, 0, 0)
|
||||
# if no wifi connection, you get spooky rainbows. Bwahahaha!
|
||||
spooky_rainbows()
|
||||
|
||||
|
||||
def spooky_rainbows():
|
||||
print("SPOOKY RAINBOWS!")
|
||||
HUE_START = 30 # orange
|
||||
HUE_END = 140 # green
|
||||
SPEED = 0.3 # bigger = faster (harder, stronger)
|
||||
|
||||
distance = 0.0
|
||||
direction = SPEED
|
||||
while True:
|
||||
for i in range(NUM_LEDS):
|
||||
# generate a triangle wave that moves up and down the LEDs
|
||||
j = max(0, 1 - abs(distance - i) / (NUM_LEDS / 3))
|
||||
hue = HUE_START + j * (HUE_END - HUE_START)
|
||||
|
||||
led_strip.set_hsv(i, hue / 360, 1.0, 0.8)
|
||||
|
||||
# reverse direction at the end of colour segment to avoid an abrupt change
|
||||
distance += direction
|
||||
if distance > NUM_LEDS:
|
||||
direction = - SPEED
|
||||
if distance < 0:
|
||||
direction = SPEED
|
||||
|
||||
time.sleep(0.01)
|
||||
|
||||
|
||||
def hex_to_rgb(hex):
|
||||
|
|
Ładowanie…
Reference in New Issue