Question
Exercise #1 Write a program in Python that uses the button to increment the count displayed on the seven segment display. The counter will increase
Exercise #1
Write a program in Python that uses the button to increment the count displayed on the seven segment display. The counter will increase if the button is depressed, and remain the same otherwise.
Exercise #2
Now, we are going to write a program in Python inspired by the reaction tester at the Ontario Science Centre. The tester is similar in appearance to the drivers seat of a vehicle. The simulation starts when the user presses the accelerator pedal. At a random time, a STOP indicator is shown. When the user sees the STOP indicator, they are supposed to hit the brake pedal. The tester then shows you a comparative view of your reaction time.
Write a program that displays go to simulate acceleration. It will then delay for a random amount of time (between 2 seconds and 5 seconds in duration), before displaying stop. To generate a random number and sleep for that amount of time (in seconds):
import time import random delay = random.randrange(2000, 5000) / 1000.0 time.sleep(delay)
Once stop is displayed, record the time and start polling the button input (GPIO #17). Then the button is pressed, record the time again. Use the following code as a template:
import datetime startTime = datetime.datetime.now() ... do something ... endTime = datetime.datetime.now() elapsed = endTime - startTime elapsedSeconds = elapsed.total_seconds()
Display the users reaction time using the seven segment display.
Note: You will have to do your best to display go and stop, as the seven segment display is intended for decimal digits.
D.5b 7-segment LED HT15K33 Backpack fritzing D.5b 7-segment LED HT15K33 Backpack fritzingStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started