State Diagram
Why This Example?
The turnstile is the canonical first FSM example. It has:
• Only 2 states (Locked, Unlocked)
• Only 2 inputs (Coin, Push)
• Clear real-world behavior everyone understands
• Only 2 states (Locked, Unlocked)
• Only 2 inputs (Coin, Push)
• Clear real-world behavior everyone understands
Transition Table
| State | Input | Next State | Output |
|---|---|---|---|
| LOCKED | coin | UNLOCKED | unlock |
| LOCKED | push | LOCKED | alarm! |
| UNLOCKED | coin | UNLOCKED | (none) |
| UNLOCKED | push | LOCKED | lock |
Try It!
🔒 LOCKED
Inputs
Current Behavior
LOCKED: Insert a coin to unlock.
Pushing will trigger an alarm (you haven't paid!).
Event Log
Turnstile initialized in LOCKED state