]> vault307.fbx.one Git - LEDstrand.git/blob - main.py
twinkling purple/pink lights
[LEDstrand.git] / main.py
1 # Imports
2 from machine import Pin
3 from neopixel import NeoPixel
4 import time, random
5
6 # LED details
7 GPIOnumber = 28
8 LEDcount = 15
9
10 # set up buttons
11 cBtn=Pin(16,Pin.IN,Pin.PULL_UP)
12 sBtn=Pin(17,Pin.IN,Pin.PULL_UP)
13
14 # Define the strand pin number and number of LEDs from variables
15 strand = NeoPixel(Pin(GPIOnumber), LEDcount)
16
17 global mycolour
18 mycolour=(78,0,45)
19 pink=(253,58,73)
20 # Turn off all LEDs before program start
21 strand.fill((mycolour))
22 strand.write()
23 time.sleep(1)
24
25 def ledStrand():
26 i=random.randint(0,LEDcount-1)
27 strand[i]=(mycolour)
28 strand.write()
29 time.sleep(.09)
30 strand[i]=(pink)
31 strand.write()
32 time.sleep(1.09)
33
34 def nColor():
35 global mycolour
36 mycolour=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
37 time.sleep(0.09)
38
39 def clearStrand():
40 strand.fill((0,0,0))
41 strand.write()
42
43 while True:
44 ledStrand()
45 if sBtn.value()==0:
46 clearStrand()
47 break
48 if cBtn.value()==0:
49 nColor()
50
51