Simple state machine with switch-case
📖 Scenario: You are programming a simple traffic light controller for a small intersection. The traffic light cycles through three states: RED, GREEN, and YELLOW. Each state lasts for a certain number of seconds before switching to the next.
🎯 Goal: Build a simple state machine using switch-case in C to cycle through the traffic light states and print the current state.
📋 What You'll Learn
Create an enum for the traffic light states: RED, GREEN, YELLOW
Create a variable called
current_state to hold the current stateUse a
switch-case statement to handle state transitionsPrint the current state name in each case
💡 Why This Matters
🌍 Real World
Traffic lights and many devices use state machines to control behavior based on current conditions.
💼 Career
Understanding state machines and switch-case logic is essential for embedded systems programming and device control.
Progress0 / 4 steps