]> vault307.fbx.one Git - random.git/blob - letITglowthread.py
different projects to learn new things
[random.git] / letITglowthread.py
1 from machine import Pin
2 from neopixel import NeoPixel
3 import time, _thread, random
4
5 # Set up LED pins
6 seg1 = Pin(0, Pin.OUT)
7 seg2 = Pin(1, Pin.OUT)
8 seg3 = Pin(2, Pin.OUT)
9 seg4 = Pin(3, Pin.OUT)
10 seg5 = Pin(4, Pin.OUT)
11 seg6 = Pin(6, Pin.OUT)
12
13 # Create a list of our LEDs
14 segments = [seg1, seg2, seg3, seg4, seg5, seg6]
15
16 # Set up buttons
17 greenbtn = Pin(14, Pin.IN, Pin.PULL_DOWN)
18 redbtn = Pin(15, Pin.IN, Pin.PULL_DOWN)
19
20 # Define the strip pin number (2) and number of LEDs (12)
21 ring = NeoPixel(Pin(16), 12)
22
23 # Initialize ring
24 ring.fill((0,0,0))
25 ring.write()
26 time.sleep(1)
27
28 #r = random.randint(0,100)
29 #g = random.randint(0,100)
30 #b = random.randint(0,100)
31
32 #while True:
33 def ledScan():
34 # For loop to turn each LED on then off in order of the list
35 for led in segments:
36
37 led.value(1)
38 time.sleep(0.08)
39 led.value(0)
40 # For loop in reverse, running backwards through the list
41 for led in reversed (segments):
42
43 led.value(1)
44 time.sleep(0.08)
45 led.value(0)
46
47 def colorRing():
48 # Create random RGB values
49 r = random.randint(0,100)
50 g = random.randint(0,100)
51 b = random.randint(0,100)
52
53 for i in range(12):
54
55 # Light each LED a random colour
56 ring[i] = (r,g,b)
57 ring.write()
58
59 # Show the LED for this long
60 time.sleep(0.05)
61
62 #Clear the ring at the end of each loop
63 #ring.fill((0,0,0))
64 ring.write()
65 while True:
66 #ledScan()
67 if greenbtn.value()==1:
68 _thread.start_new_thread(colorRing(),())
69 if redbtn.value()==1:
70 ring.fill((0,0,0))
71 ring.write()
72 ledScan()