Skip to content

Instantly share code, notes, and snippets.

@uktechreviews
Created August 21, 2017 16:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save uktechreviews/981b1691550930d85c759e57dbe175c9 to your computer and use it in GitHub Desktop.
Save uktechreviews/981b1691550930d85c759e57dbe175c9 to your computer and use it in GitHub Desktop.
from gpiozero import Button
from gpiozero import LED
from time import *
import time
import random
button = Button(21)
green =LED(14)
yellow=LED(15)
green.on()
yellow.off()
wait = random.randint(2,7)
sleep(wait)
start_time = time.time()
while True:
if button.is_pressed:
yellow.off()
end_time = time.time()
elapsed_time = end_time - start_time
print ("You took " + "%.2f" %elapsed_time + " seconds")
break
else:
yellow.on()
green.off()
green.off()
yellow.off()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment