Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from gpiozero import LED, Button
- from random import randint
- from time import sleep, time, gmtime
- red_led = LED(17)
- button = Button(4)
- reset_button = Button(3)
- highscore = 100 #inital highscore as time to beat
- reset_button_state = 0
- def highscore_reset():
- global reset_button_state
- global highscore
- highscore = 100
- while True:
- sleep(randint(1,10))
- red_led.on()
- start = time()
- button.wait_for_press()
- red_led.off()
- end = time()
- react = end - start
- print('highscore is: ' + str(highscore))
- print('your time is : ' + str(react))
- if react < highscore:
- print('congrats new highscore! well done!')
- highscore = react
- else:
- print('try again!')
- reset_button.when_pressed = highscore_reset
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement