Kyle Chuang | ME405 Mechatronics Portfolio
me405L2.py File Reference

Labx02: Think Fast! More...

Functions

def me405L2.myCallback (IQR_source)
 Callback function. More...
 

Variables

 me405L2.tim = pyb.Timer(2, prescaler=79, period=0x7FFFFFFF)
 Creates an emergency buffer to store errors that are thrown inside ISR. More...
 
 me405L2.pinA5 = pyb.Pin(pyb.Pin.cpu.A5, mode=pyb.Pin.OUT_PP)
 Initializes the LED.
 
 me405L2.pinC13 = pyb.Pin(pyb.Pin.board.PC13, mode=pyb.Pin.IN)
 Pin for blue USER button.
 
int me405L2.run_count = 0
 Variable that tracks number of runs.
 
 me405L2.timer_count = None
 Timer object.
 
list me405L2.rxn_times = []
 List of recorded reaction times.
 
 me405L2.extint = pyb.ExtInt (pinC13, pyb.ExtInt.IRQ_FALLING, pyb.Pin.PULL_UP, myCallback)
 Detects when the USER button is pressed and the callback function is called.
 
 me405L2.random_delay = random.randrange(2000,3000)
 Will choose a random number from 2000 (2 seconds) and 3000 (3 seconds). More...
 
 me405L2.avg = round((sum(rxn_times) / len(rxn_times)), 3)
 

Detailed Description

Labx02: Think Fast!

I wrote this code to test the reaction time of the user. A Nucleo L476RG board is required to facilitate this test. When the code is run, 2-3 seconds will pass before the LD2 LED will light up and a timer starts. The timer will end once the user presses the blue USER button, and the reaction time will be reported in seconds. If the user does not press the button within 1 second of the LED being turned on, the light will automatically be turned off, an error message will print, and the run will not be counted.

The trials will repeat for as long as the user pleases. Once the user is done, they can exit the program by pressing "Ctrl + c" on the keyboard. This will exit the program and report the average reaction time from all the trials.

Author
Kyle Chuang
Date
January 23, 2021

Function Documentation

◆ myCallback()

def me405L2.myCallback (   IQR_source)

Callback function.

This is the callback function that is used when the user clicks the blue USER button. This will overrite the code in the while True statement, turn off the LED and it will record the time.

Variable Documentation

◆ random_delay

me405L2.random_delay = random.randrange(2000,3000)

Will choose a random number from 2000 (2 seconds) and 3000 (3 seconds).

This will be the delay before the LED turns on.

◆ tim

me405L2.tim = pyb.Timer(2, prescaler=79, period=0x7FFFFFFF)

Creates an emergency buffer to store errors that are thrown inside ISR.

Creates a timer variable.