Light Switch

STM32 Read Button State Exercise

Task

While your program runs, the button on PA0 is pressed and released. Read it and control the LED on PA5: if the button is pressed -> LED on; if not pressed -> LED off. Repeat this for as long as the board runs. The registers and bit fields are on the Datasheet tab.

Circuit

Block diagram: SW1 pushbutton from +3V3 into U1 STM32F4 pin PA0, held low by R2 10k to ground when released, and pin PA5 driving R1 330R into D1 LED to ground, with a TP1 logic analyzer probe on the PA5 net

Pass condition

PA5 must match PA0 at all times, with no extra edges.

Expected output: PA0 pressed twice, and PA5 following it with four edges, first rising and last falling

Notes

This question needs no clock enable.

Related challenges

In interview questions

Loading the interactive arena.