LED Status FSM

Easy C FSM
Solve this problem

Implement an embedded C FSM to control LED status based on system mode. The LED should remain OFF during IDLE, blink at 1 Hz in ACTIVE mode, and blink at 4 Hz in ERROR mode. The FSM must run per tick call.

Constraints

  • Mode enum: IDLE, ACTIVE, ERROR.
  • tick() function toggles LED based on count thresholds.
  • Blink periods: ACTIVE = 500 ms, ERROR = 125 ms.
  • tick() is called every 125 ms.
  • LED state persists across calls.
  • Mode change immediately affects blinking.
Starter codeC
1#include <stdint.h>2 3enum mode {IDLE, ACTIVE, ERROR};4void set_mode(enum mode m);5uint8_t tick(); // returns LED state