CALPOLY MECHATRONICS
Documentation for all Mechatronics Labs
ME405 LAB0x02: Reaction Time Measuring


The goal of this lab was to use interrupts on the Nucleo to accuratley measure the user's reaction time.

Specifically, the Nucleo waits a random amount of time between 2 and 3 seconds, then turns the green built in LED on. The user must then press the blue "User" button on the Nucleo as fast as possible and the program will measure their reaction time. This process repeates until the user presses ctrl+c to exit the program, at which point the Nucleo prints out their average reaction time and the number of attempts they did. If there were no recorded attempts the Nucleo will print out an error message instead.

For my implementation of this project I chose to use a finite state machine that switches between 3 states:

  • state 0: led off and waiting
  • state 1: led on for one second
  • state 2: updating average reaction time and reseting values

Note that the users reaction time is measured using an interrupt, which can occur at any point in the FSM. However, to avoid incorrect readings, I have configured the interrupt to only record the users reaction time if it is the first time they have pressed the button after the led has turned on (ie the FSM is in state 1).

I implemented the reaction time measuring system in two different ways. The first was using utime.ticks_us() and utime.ticks_diff() To record the users reaction time when they pressed the button. The second method used the built in timer modules in micro python to both turn the led on and off and record when the user presses the button.