ME 405: Mechatronics Portfolio
ReactionTest.py File Reference

Created on Thu Jan 21 08:17:48 2021. More...

Functions

def ReactionTest.buttonPress (which_pin)
 Button press function for external interrupt. More...
 

Variables

 ReactionTest.extint = ExtInt(pyb.Pin.cpu.C13,pyb.ExtInt.IRQ_FALLING,pyb.Pin.PULL_UP,buttonPress)
 Set up external interrupt on button C13 of STM32-NUCLEO-L476RG.
 
 ReactionTest.tim = pyb.Timer(2,period = 0x7FFFFFFF, prescaler = 83)
 Set up timer 2 for interrupts, scaling to count in microseconds.
 
 ReactionTest.LED = pyb.Pin(pyb.Pin.cpu.A5)
 Set up LED pin A5 on MCU.
 
bool ReactionTest.buttonFlag = False
 Define flag for button presses.
 
bool ReactionTest.firstFlag = True
 Define flag to determine whether initial print statement should show.
 
 ReactionTest.startTime = tim.counter()
 Record the start count for the timer in microseconds.
 
 ReactionTest.currTime = tim.counter()
 Update the current count for the timer in microseconds.
 
 ReactionTest.split = currTime - startTime
 Calculate the reaction time of the user.
 

Detailed Description

Created on Thu Jan 21 08:17:48 2021.

Author
Miles Young
Date
01/21/2021

Reaction time testing game
This program tests the user's reaction time, similar to the popular 90's toy Bop-it. The program employs an external interrupt associated with a built-in button on the board to quickly determine when the button has been pressed. To begin the game, the user is prompted to press the button at least once. When the user has done this, a green built-in LED will light up at a random time between 2 and 3 seconds after the starting press and stay lit for 1 second. Once the LED has lit, the user must press the button at least once more to stop the stopwatch. The time recorded by the stopwatch will then be printed, and the game will reset. If the user fails to press the button before the LED turns off, a motivational message is printed.

Function Documentation

◆ buttonPress()

def ReactionTest.buttonPress (   which_pin)

Button press function for external interrupt.

This function is called by the external interrupt on the built-in button C13. It changes a global variable buttonFlag to true if it is currently false, or else keeps it true if it is currently true. This is intended to allow the button to be pressed multiple times, with manual resets of buttonFlag required in the body of the program.