Created
August 3, 2017 09:43
-
-
Save uktechreviews/efdfa8388693a9feb74965b5d4e2bef0 to your computer and use it in GitHub Desktop.
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
from gpiozero import Button | |
from gpiozero import LED | |
from time import * | |
import time | |
import random | |
button = Button(21) | |
green =LED(2) | |
yellow=LED(3) | |
speed = int(input("Enter your speed in miles per hour: ")) | |
speed2 = speed * 0.44704 | |
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 | |
thinking = elapsed_time * speed2 | |
print ("You took " + "%.2f" %elapsed_time + " seconds") | |
print ("At " + str(speed) + " mph your thinking distance is ") | |
print ("%.2f" %thinking + " m") | |
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