This file runs a Think Fast game on the nucleo. More...
Functions | |
| def | Lab_02.UserInterrupt (pin) |
| This is the callback function for the user button press. More... | |
| def | Lab_02.CalcAvg (time, timer) |
| This function converts timer output to seconds. More... | |
| def | Lab_02.ReturnResults (timer) |
| This function prints the users performance results. More... | |
| def | Lab_02.TimerCallback (timer) |
| This is the callback function in case of timer overflow. More... | |
Variables | |
| Lab_02.pinA5 = pyb.Pin(pyb.Pin.cpu.A5 , pyb.Pin.OUT_PP) | |
| Setting up Nucleo LED. | |
| int | Lab_02.reaction_time = 0 |
| Variable representing the reaction time of a single user attempt. | |
| int | Lab_02.total_reaction_time = 0 |
| Variable representing sum of all reaction times. | |
| int | Lab_02.attempts = 0 |
| Variable representing the number of game attempts by user. | |
| Lab_02.Interrupt_Button = pyb.ExtInt(pyb.Pin.board.PC13, pyb.ExtInt.IRQ_RISING, pyb.Pin.PULL_UP, UserInterrupt) | |
| Defining nucleo user input button as external interrupt. | |
| bool | Lab_02.input_status = True |
| Tracks if the user has pressed the input button. | |
| Lab_02.sleep_time = urandom.randint(int(2e6) , int(3e6)) | |
| Variable representing random time between 2 and 3 seconds. | |
| Lab_02.button_timer = pyb.Timer(2 , period = int(pyb.freq()[2])-1 , prescaler = 0 , callback = TimerCallback) | |
This file runs a Think Fast game on the nucleo.
This program prompts the user to press a button on the nucleo after they have seen an LED turn on. The program makes use of an external interrupt(the button) to break a while loop and collect data on every user input. If either the user presses ctrl-c or waits too long after an LED flash, the program prints the users average response time based on all of their attempts.
| def Lab_02.CalcAvg | ( | time, | |
| timer | |||
| ) |
This function converts timer output to seconds.
The nucleo timer responds in counts, so this function converts the timer counts to seconds by dividing by the frequency and period.
| time | The amount of time to be converted. |
| def Lab_02.ReturnResults | ( | timer | ) |
This function prints the users performance results.
After either pressing ctrl-c or waiting too long on an attempt, this function then provides the user with their performance data. Assuming the user made at least one attempt it will print the average reaction time, otherwise it will print N/A. This function then deactivates the timer and interrupt button, and turns the LED off.
| timer | This fulfills the parameter requirement. |
| def Lab_02.TimerCallback | ( | timer | ) |
This is the callback function in case of timer overflow.
The timer is set up such that it overflows at 1 second which runs this function. This overflow function changes the input status parameter to False and prints Too Slow. Ultimately this leads the program to print results and end.
| timer | Unused parameter to fulfill callback parameter requirement. |
| def Lab_02.UserInterrupt | ( | pin | ) |
This is the callback function for the user button press.
This function runs on every button press and collects data on the user's performance. This function updates both the total response time and number of attempts which are ultimately used to calculate the users average response time.
| pin | This fulfills the parameter requirement of the callback fcn. |