60. LED Patterns Switching

We need to toggle between two LED blinking patterns using a push-button, while the main loop is busy with other tasks.
To ensure instant response and non-blocking operation, we use interrupts.

Implementation Concept

  1. External Interrupt:
    • Triggered on a button press to change the LED pattern immediately.
    • Detects input changes without polling in the main loop.
  2. Timer Interrupt:
    • Generates periodic events to toggle LEDs for blinking or debouncing the switch.
    • Keeps LED timing independent of main loop load.

Hardware Setup

  • Connect two LEDs with appropriate current-limiting resistors to limit the current to 10 mA.
  • One push-button configured to provide clean HIGH/LOW levels (with pull-up or pull-down).

So, by selecting a proper resistor, LED, and push-button switch correctly, we can implement the task.

Below are the solutions to the given task using different microcontrollers

  1. STM32
  2. ESP32
  3. Arduino UNO

Submit Your Solution

Note: Once submitted, your solution goes public, helping others learn from your approach!