Created
April 10, 2020 19:35
-
-
Save oschettler/4445a9a0cd8c989c094ea24473bf65df to your computer and use it in GitHub Desktop.
Reaction game with highscore
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Reaction game | |
from gpiozero import Button, LED | |
from time import time, sleep | |
from random import randint | |
from gpiozero.pins.pigpio import PiGPIOFactory | |
factory = PiGPIOFactory(host='raspberrypi') | |
led = LED(17, pin_factory=factory) | |
btn = Button(4, pin_factory=factory) | |
highscore = 10 | |
while True: | |
sleep(randint(1,10)) | |
led.on() | |
start = time() | |
btn.wait_for_press() | |
led.off() | |
end = time() | |
score = end - start | |
if score < highscore: | |
print(score, "- new highscore!") | |
highscore = score | |
else: | |
print(score, "- highscore:", highscore) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment