python-telemetrix-ambilight/single_speed_particles.py

48 lines
1.1 KiB
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
import numpy
from scipy.ndimage.interpolation import shift
from time import perf_counter as millis
import threading
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()
NUM_LEDS = 60
TIME_UNIT = 0.1
global spaces
spaces = numpy.zeros(NUM_LEDS)
board.set_pin_mode_neopixel(pin_number=2,num_pixels=NUM_LEDS)
board.neopixel_clear(auto_show=True)
def updateLED():
for i in range(0,NUM_LEDS):
board.neo_pixel_set_value(i,r=int(spaces[i]*255),g=int(spaces[i]*255),b=int(spaces[i]*255))
board.neopixel_show()
def advanceTimeUnit():
global spaces
while True:
spaces = shift(spaces,1,cval=0)
updateLED()
delay(TIME_UNIT)
atu = threading.Thread(target=advanceTimeUnit)
atu.start()
while True:
input("Press Enter to Particle")
spaces[0] = 1