Uses an OC/IC method to compute the average reaction time for the user to press a button after an LED turns on. More...
Functions | |
| def | ME405_Lab0x02_PartB.OC_Compare (tim2) |
| Callback func. More... | |
| def | ME405_Lab0x02_PartB.IC_Capture (tim2) |
| Callback func. More... | |
Variables | |
| int | ME405_Lab0x02_PartB.successCntr = 0 |
| A counter that increments each time the user presses the button while the LED is on. | |
| int | ME405_Lab0x02_PartB.failCntr = 0 |
| A counter that is added to whenever the user mistimes their button press. | |
| ME405_Lab0x02_PartB.correctPress = None | |
| bool | ME405_Lab0x02_PartB.isBP = False |
| int | ME405_Lab0x02_PartB.lastCompare = 20000 |
| Specifies the initial count value at which a compare match will trigger. | |
| ME405_Lab0x02_PartB.lastCapture = None | |
| The variable to which the count value associated with the button press will be appended. | |
| int | ME405_Lab0x02_PartB.ledOn = 0 |
| int | ME405_Lab0x02_PartB.ledOff = 0 |
| ME405_Lab0x02_PartB.pinA5 = pyb.Pin(pyb.Pin.cpu.A5) | |
| ME405_Lab0x02_PartB.pinB3 = pyb.Pin(pyb.Pin.cpu.B3) | |
| ME405_Lab0x02_PartB.tim2 = pyb.Timer(2, period = 0xffff, prescaler = 4900) | |
| Establishes the timer used. | |
| ME405_Lab0x02_PartB.t2ch2 = tim2.channel(2, pyb.Timer.IC, pin=pinB3, polarity = Timer.FALLING, callback = IC_Capture) | |
| Sets timer to IC mode, then sets relavant pins, triggering periods, and callbacks. | |
| ME405_Lab0x02_PartB.t2ch1 = tim2.channel(1, pyb.Timer.OC_TOGGLE, pin=pinA5, callback = OC_Compare) | |
| Sets timer to OC mode, then sets relavant pins, triggering periods, and callbacks. | |
| int | ME405_Lab0x02_PartB.totalGames = successCntr + failCntr |
| int | ME405_Lab0x02_PartB.rateOfSuccess = successCntr/totalGames |
| Tabulates the number of games the user played successfully. | |
Uses an OC/IC method to compute the average reaction time for the user to press a button after an LED turns on.
source code: https://bitbucket.org/nicho755/me-305-labs/src/master/ME405_Lab0x02_ThinkFast/ME405_Lab0x02_PartB.py
| def ME405_Lab0x02_PartB.IC_Capture | ( | tim2 | ) |
Callback func.
that triggers when the button is pressed
The input capture function sets the value of a lastCapture variable to the time when the button was pressed. Additionally, it sets a global variable serving as a conditional to a value of "True", which will be used in the OC_Compare callback to evaluate if the button was pressed in the appropriate amount of time.
| def ME405_Lab0x02_PartB.OC_Compare | ( | tim2 | ) |
Callback func.
that sets output compare value and evaluates button push
A collection of global variables are used to evaluate whether or not the button was pushed at the appropriate time. The LED is cycled in 1 seocnd intervals. While the LED is on, if the user hits the button, their victory will be recorded.