-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsimonbreak.py
51 lines (43 loc) · 1002 Bytes
/
simonbreak.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import time
TIME = 0.1
import RTk.GPIO as GPIO
from threading import Thread
BUTTON = 25
RED =24
YEL =23
GRN=22
GPIO.setmode(GPIO.BCM)
GPIO.setup(RED, GPIO.OUT)
GPIO.setup(YEL, GPIO.OUT)
GPIO.setup(GRN, GPIO.OUT)
GPIO.setup(BUTTON, GPIO.IN,pull_up_down=GPIO.PUD_UP)
GPIO.output(GRN, True)
def pinread():
while True:
time.sleep(TIME)
b = GPIO.input(BUTTON)
if not b:
print("pressed")
else:
print("released")
def pinwrite():
while True:
GPIO.output(GRN, False)
GPIO.output(YEL, True)
time.sleep(TIME * 10)
GPIO.output(YEL, False)
GPIO.output(RED, True)
time.sleep(TIME * 10)
GPIO.output(YEL, True)
time.sleep(TIME * 10)
GPIO.output(RED, False)
GPIO.output(YEL, False)
GPIO.output(GRN, True)
time.sleep(TIME * 10)
try:
i = Thread(target=pinread)
i.start()
o = Thread(target=pinwrite)
o.start()
finally:
GPIO.cleanup()