-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTheGame.py
More file actions
35 lines (29 loc) · 1003 Bytes
/
TheGame.py
File metadata and controls
35 lines (29 loc) · 1003 Bytes
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
# Reaction Game
# Ahmad Hussain 2017
from gpiozero import LED, Button
import time
from time import sleep
from random import uniform
import sys
led = LED(4)
right_button = Button(15)
left_button = Button(14)
#assigning the hardware to the respective GPIO pins
while True:
led.on()
if(right_button.is_pressed or left_button.is_pressed):
led.off()
sys.exit("You pressed too early") #ends the game
sleep(uniform(2, 5))
led.off() #tuns the LED off after anywhere between 2-5 seconds
break
float start = time.time() #starts the timer
while True:
if right_button.is_pressed:
float elapsed = time.time() - start #calculates reaction time
print("Right player wins, your reaction time was " + elapsed + " seconds")
break
else if left_button.is_pressed:
float elapsed = time.time() - start #calculates reaction time
print("Left player wins, your reaction time was " + elapsed + " seconds")
break