The ON/OFF button
The Nucleo board has a user programmable push button. We will now use it as an ON/OFF button for the alien voice effect.
Configuration
The idea is to use the push button to call an asynchronous routine in our code. To do that, we need to configure the button to trigger an interrupt and then we need to catch the interrupt in our code.
Go into CubeMX by clicking on the ioc
file in your alien voice project; in the left panel click on "System > NVIC" and enable the line "EXTI line 4 to 15" by checking the corresponding checkmark. The pin PC13 is linked to EXTI13 in the hardware of the microcontroller. Interrupts are used because they provide a very fast access to the core of the system and thus a very fast reaction.
Still in CubeMX, verify that the label for pin PA5 is "LD2" and the label for pin PC13 is "B1".
Add the following state variable to the USER CODE BEGIN PV
section
and add the following interrupt handler to the USER CODE BEGIN 0
section:
The interrupt handler toggles the variable user_button
and switches the LED on when its value is true.
TASK 1: Modify the alien voiceProcess
function so that it switches between a passthrough and the alien voice.
Benchmarking
Now that we have an ON/OFF button, we can use the benchmarking timer we defined before to see how expensive it is to compute the alien voice.
TASK 2: Add the timing macros to the Process function and use the push button to compare execution times.
Solution
Are you sure you are ready to see the solution? ;)
Last updated