]> vault307.fbx.one Git - random.git/blob - ledTWINKLE.py
different projects to learn new things
[random.git] / ledTWINKLE.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 # Turn off all LEDs before program start
20 strand.fill((mycolour))
21 strand.write()
22 time.sleep(1)
23
24 def ledStrand():
25 i=random.randint(0,LEDcount-1)
26 strand[i]=(0,0,0)
27 strand.write()
28 time.sleep(0.09)
29 strand[i]=(mycolour)
30 strand.write()
31 time.sleep(0.09)
32
33 def nColor():
34 global mycolour
35 mycolour=(random.randint(0,255),random.randint(0,255),random.randint(0,255))
36 time.sleep(0.09)
37
38 def clearStrand():
39 strand.fill((0,0,0))
40 strand.write()
41
42 while True:
43 ledStrand()
44 if sBtn.value()==0:
45 clearStrand()
46 break
47 if cBtn.value()==0:
48 nColor()