python-telemetrix-ambilight/rainbow.py

29 lines
807 B
Python
Raw Permalink Normal View History

2022-03-30 13:15:41 +00:00
from telemetrix_rpi_pico import telemetrix_rpi_pico
from time import sleep as delay
import signal
import sys
import colorsys
from time import perf_counter as millis
def sigint_handler(signal, frame):
print ('KeyboardInterrupt is caught')
board.shutdown()
sys.exit(0)
signal.signal(signal.SIGINT, sigint_handler)
board = telemetrix_rpi_pico.TelemetrixRpiPico()
board.set_pin_mode_neopixel(pin_number=2,num_pixels=60)
board.neopixel_clear(auto_show=True)
SEGMENT_SIZE = 1
VELOCITY = 10
NUM_LEDS = 60
color = []
k = 0
timecounter = 0
while(True):
for j in range(0,NUM_LEDS):
2022-04-01 10:39:15 +00:00
r, g, b = colorsys.hsv_to_rgb(((-timecounter*VELOCITY+j*2)%360)/360,1,1)
2022-03-30 13:15:41 +00:00
board.neo_pixel_set_value(j,r=int(r*255),g=int(g*255),b=int(b*255))
timecounter+=1
2022-04-01 10:39:15 +00:00
delay(0.05)
2022-03-30 13:15:41 +00:00
board.neopixel_show()