ME 405 Portfolio
Lab2.py File Reference

Reaction Time Game. More...

Functions

def Lab2.count_isr (PC13)
 Button Push ISR. More...
 

Variables

 Lab2.blinky = pyb.Pin(pyb.Pin.board.PA5, mode = pyb.Pin.OUT_PP)
 set led as blinky More...
 
int Lab2.blinky_status = 0
 Blinky Flag. More...
 
int Lab2.reaction_sum = 0
 Sum of the past reaction times. More...
 
int Lab2.reaction_num = 0
 Number of times played. More...
 
int Lab2.counter_status = 0
 Time on the counter. More...
 
int Lab2.random_time = 0
 A random time. More...
 
int Lab2.average_response = 0
 Value of Average. More...
 
int Lab2.state = 0
 Value of the state. More...
 
 Lab2.tim = pyb.Timer(2, prescaler=79, period = 0x3fffffff)
 Timer Object. More...
 
 Lab2.extint
 External Interrupt Variable. More...
 

Detailed Description

Reaction Time Game.

Program initializes and prompts you to play a game in which you will attempt to press the blue button on our microcontroller as soon as you see the green light turn on. Once you press it, the green light will turn off and your reaction time will be presented in microseconds, and it will wait a random time period between 0 and 6 seconds to turn on again. If you do not press the green light within 1 second, it will automatically exit and the game will be over. When the user presses control-c, their average time will be presented in seconds. (That is how I understood this assignment.)

Author
Jacob Everest
Date
Jan. 21, 2021

Function Documentation

◆ count_isr()

def Lab2.count_isr (   PC13)

Button Push ISR.

When the user presses the PC13 button, the program will jump here. This ISR will determine if the LED was on. If so it will record the user reaction time, display that, add that time to the sum of their reaction times, and increment the number of times they have played.

Parameters
PC13the value of the pin to be pushed on the microcontroller
Author
Jacob Everest
Date
Jan. 21, 2021

Variable Documentation

◆ average_response

tuple Lab2.average_response = 0

Value of Average.

Average response of the user after exiting

◆ blinky

Lab2.blinky = pyb.Pin(pyb.Pin.board.PA5, mode = pyb.Pin.OUT_PP)

set led as blinky

When I refer to blinky, I am refering to the LED pin on the board

◆ blinky_status

int Lab2.blinky_status = 0

Blinky Flag.

Always set as either 0 if blinky is off or 1 if blinky is on this will be used to let the interrupt know whether the button has been pressed appropriately or not.

◆ counter_status

int Lab2.counter_status = 0

Time on the counter.

Stores the time on the counter when the user interrupted

◆ extint

Lab2.extint
Initial value:
1 = pyb.ExtInt (pyb.Pin.board.PC13,
2  pyb.ExtInt.IRQ_FALLING,
3  pyb.Pin.PULL_UP,
4  count_isr)

External Interrupt Variable.

Calls the external interrupt function that we created earlier

◆ random_time

Lab2.random_time = 0

A random time.

Used to store a random time between 0 and 6 seconds for the LED to turn on

◆ reaction_num

int Lab2.reaction_num = 0

Number of times played.

Number of reaction times by the user, used to compute the average

◆ reaction_sum

int Lab2.reaction_sum = 0

Sum of the past reaction times.

adds up the reaction times to compute the average later

◆ state

int Lab2.state = 0

Value of the state.

I still have 305 assembly language PTSD. I can't not use states

◆ tim

Lab2.tim = pyb.Timer(2, prescaler=79, period = 0x3fffffff)

Timer Object.

Timer object on timer 2 with a prescaler of 79 and a period of 0x3fffffff