A bare-metal STM32 firmware project that counts button presses and displays the count using LED blink codes.
This project is implemented using direct register manipulation without HAL libraries.
The firmware has two operating phases.
- Press the onboard button between 1 and 9 times.
- Every valid press produces a short LED flash.
- If no button is pressed for approximately two seconds, the firmware switches to display mode.
The LED blinks back the number of recorded button presses.
Example
If the button was pressed four times:
Blink
Blink
Blink
Blink
Pause
Repeat
During display mode, pressing the button resets the counter and returns the firmware to counting mode.
- STM32 NUCLEO-F446RE
- USB Cable
No external hardware is required.
| Function | Pin |
|---|---|
| LED | PA5 |
| Button | PC13 |
- Register-level GPIO programming
- Memory-mapped I/O
- RCC clock enabling
- Active LOW button logic
- Polling
- Software debouncing
- Edge detection
- Timeout detection
- Counter variables
- Two-phase state machine
- LED data encoding
COUNTING
|
| 2 seconds without button press
V
DISPLAYING
|
| Button Press
V
COUNTING
- Open STM32CubeIDE
- Create a project for the NUCLEO-F446RE
- Replace
Core/Src/main.c - Build
- Flash
- Run
stm32-press-counter-led-codes
│
├── README.md
├── .gitignore
├── docs
│ └── wiring.md
└── src
└── main.c
- Timer interrupts
- UART output
- Seven-segment display
- LCD interface
- Persistent storage