def start(pin,numpins): global leds,layer0,layer1,layer2,npins npins=numpins leds = neo.ledstrip(pin,numpins) layer0 = neo.ledstrip(pin,numpins) layer1 = neo.ledstrip(pin,numpins) layer2 = neo.ledstrip(pin,numpins) setup_anim(0) setup_anim_speed(50) # start the background animation thread thread(animate_background,500) # start the foreground animation thread thread(animate_foreground,50) while True: # clear leds leds.clear() # now, acquire the lock lock.acquire() # merge the first and second layer leds.merge(layer0) leds.merge(layer1) # merge the background layer only where leds is transparent (0,0,0) leds.merge(layer2,neo.first_color) # release the lock lock.release() # and light it up! leds.on() sleep(50)
################################################################################ # Neopixel LED Strips # # Created by VIPER Team 2015 CC # Authors: G. Baldi, D. Mazzei ################################################################################ import threading from drivers.neopixel import ledstrips as neo # create all the needed layers leds = neo.ledstrip(D6, 16) layer0 = neo.ledstrip(D6, 16) layer1 = neo.ledstrip(D6, 16) layer2 = neo.ledstrip(D6, 16) # fill layers with their initial values leds.clear() layer0[0] = (100, 0, 0) layer0[1] = (100, 0, 0) layer0[2] = (100, 0, 0) layer1[0] = (0, 100, 0) layer1[1] = (0, 100, 0) layer1[2] = (0, 100, 0) layer2.clear() # let's define some coefficients for smooth animation (half a sinus wave) animation_coefficients = [ 0, 0.2588190451, 0.5, 0.7071067812, 0.8660254038, 0.9659258263, 1, 0.9659258263, 0.8660254038, 0.7071067812, 0.5, 0.2588190451 ]
# Neopixel LED Strips # # Created by VIPER Team 2015 CC # Authors: G. Baldi, D. Mazzei ################################################################################ # Be sure to open the serial console, otherwise the program will halt if the console buffer is full. import streams from drivers.neopixel import ledstrips as neo streams.serial() num_leds = 16 # adjust this to match the number of LEDs on your strip led_pin = D9 # this should match the data pin of the LED strip switch_pin = D2 # this should match the pin to which the button is connected leds = neo.ledstrip(led_pin, num_leds) # create a new Neopixel strip composed of <num_leds> LEDs and connected to pin D0 leds.set_fading(100, 0, 0) # create a fade effect that starts from red=100 and goes to RGB=0,0,0 # along all the available strip LEDs. This is a static setup of the LEDs pos=0 def touch(): #function to be called when a button is touched r = random(20, 100) # choose a random colour for RED g = random(20, 100) # choose a random colour for GREEN b = random(20, 100) # choose a random colour for BLUE print(r, g, b) leds.set_fading(r, g, b, num_leds-1-pos) #attach a button to pin <switch_pin> and set an interrupt to call the touched function. The button should connect the pin to Vcc. pinMode(switch_pin, INPUT_PULLDOWN)
################################################################################ # Neopixel LED Strips # # Created by VIPER Team 2015 CC # Authors: G. Baldi, D. Mazzei ################################################################################ import threading from drivers.neopixel import ledstrips as neo # create all the needed layers leds = neo.ledstrip(D6,16) layer0 = neo.ledstrip(D6,16) layer1 = neo.ledstrip(D6,16) layer2 = neo.ledstrip(D6,16) # fill layers with their initial values leds.clear() layer0[0]=(100,0,0) layer0[1]=(100,0,0) layer0[2]=(100,0,0) layer1[0]=(0,100,0) layer1[1]=(0,100,0) layer1[2]=(0,100,0) layer2.clear() # let's define some coefficients for smooth animation (half a sinus wave) animation_coefficients = [ 0, 0.2588190451, 0.5,