Skip to content

Instantly share code, notes, and snippets.

@oschettler
Created April 10, 2020 19:35
Show Gist options
  • Save oschettler/4445a9a0cd8c989c094ea24473bf65df to your computer and use it in GitHub Desktop.
Save oschettler/4445a9a0cd8c989c094ea24473bf65df to your computer and use it in GitHub Desktop.
Reaction game with highscore
# 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