-
Notifications
You must be signed in to change notification settings - Fork 0
/
YRGB.py
74 lines (67 loc) · 1.91 KB
/
YRGB.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
""" YRGB.py is derived from reaction.py :
it performs a test of the type in reaction.py for 10 times
it then relays the result as the average and the best
Tunde Adeyemo 01/21
License: Public Domain """"
import time
import digitalio
import board
import random
Yed = digitalio.DigitalInOut(board.D14)
Red = digitalio.DigitalInOut(board.D15)
Ged = digitalio.DigitalInOut(board.D17)
Bed = digitalio.DigitalInOut(board.D18)
Yed.direction = digitalio.Direction.OUTPUT
Red.direction = digitalio.Direction.OUTPUT
Ged.direction = digitalio.Direction.OUTPUT
Bed.direction = digitalio.Direction.OUTPUT
bY = digitalio.DigitalInOut(board.D1)
bR = digitalio.DigitalInOut(board.D5)
bG = digitalio.DigitalInOut(board.D6)
bB = digitalio.DigitalInOut(board.D12)
bY.direction = digitalio.Direction.INPUT
bY.pull = digitalio.Pull.UP
bR.direction = digitalio.Direction.INPUT
bR.pull = digitalio.Pull.UP
bG.direction = digitalio.Direction.INPUT
bG.pull = digitalio.Pull.UP
bB.direction = digitalio.Direction.INPUT
bB.pull = digitalio.Pull.UP
stt[]
for i in range 10:
Yed.value = False # Start with led off
Red.value = False
Ged.value = False
Bed.value = False
time.sleep(random.random()*10)
col = random.random() *4
if col <1 :
light = Yed
button =bY
else if col <2 and col >=1 :
light =Red
button =bR
else if col <3 and col >=2 :
light =Ged
button =bG
else if col >=4 :
light =Bed
button =bB
light.value = True
t0 = time.monotonic()
while light.value == True:
if button.value == False:
t = time.monotonic() - t0
print("reaction time =")
print("%.5f " %(t))
light.value = False
stt.append(t)
stm = stt[0]
for i in stt:
if i <stm :
stm = i
sts+=i
print("your average reaction time is")
print("%.5f " %(sts/10))
print("best reaction time is")
print("%.5f " %(stm))