]> vault307.fbx.one Git - Sensory_Wall.git/blob - trafficLight.py
more sensory wall projects
[Sensory_Wall.git] / trafficLight.py
1 from machine import Pin
2 import time
3 from random import randint
4
5 btn=Pin(12,Pin.IN,Pin.PULL_UP)
6
7
8 #LEDs
9 green=Pin(17,Pin.OUT)
10 yellow=Pin(14,Pin.OUT)
11 red=Pin(15,Pin.OUT)
12
13 #start with lights off
14 green.off()
15 yellow.off()
16 red.off()
17
18 #2 modes, manual and random
19 # TODO set up selector between manual (button op) and random time (randint)
20 toggle=Pin(pin,Pin.IN,Pin.PULL_UP)
21
22 def measure_tog():
23 tVal=toggle.value()
24 time.sleep(1)
25 return tVal
26 if tVal=1:
27 #run automatically, random.randint(?,?), 1 LED color at a time
28
29 if tVal=0:
30 #use button to change LED
31 green.on()
32 yellow.off()
33 red.off()
34
35 ###CREATE MAIN LOOP###
36 """ use toggle to determine which control to give (auto or manual)
37 probably check toggle status before running any subroutines, need to check status of this item first,
38 and detect fresh changes on Pin as they come in, IRQ
39 if auto, use random times to switch between lights, turning on new light, off old light
40 if manual, need to read for button presses and use that to move through lights
41 need to set up cases, OFF(no LED), RED(red only), YELLOW(yellow only), GREEN(green only)
42 """
43
44 while tval=0:
45 red.off()
46 green.on()
47 time.sleep(random.randint(5,60))
48 green.off()
49 yellow.on()
50 time.sleep(random.randint(5,60))
51 yellow.off()
52 red.on()
53 time.sleep(random.randint(5,60))