Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.60 KB | None | 0 0
  1. import time, random
  2. from gpiozero import LED, Button
  3.  
  4. led1 = LED(23)
  5. # test
  6. led1.on()
  7. time.sleep(2)
  8. led1.off()
  9.  
  10. button1 = Button(25)
  11. end = "Y"
  12. best = 100
  13. print("press buttonn when LED is on")
  14. while end =="Y":
  15.     time.sleep(random.randint(1,5))
  16.     start = time.time()
  17.     led1.on()
  18.     button1.wait_for_press()
  19.     button1.when_pressed = led1.off()
  20.     stop = time.time()
  21.     duration = stop-start
  22.     print("reaction time in s",duration)
  23.     if duration<best:
  24.         best = duration
  25.         print("You got a lowscore!")
  26.     end = input("Again [Y]es/[N]o ")#I've got no second button
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement