Skip to content
State machine (FSM) templates

Vending Machine (State Machine)

Coin collection and dispensing states.

Template previewState machine (FSM)
Vending machine3 states · 5 transitions · 4 eventsinsert_coininsert_coinenough_paiditem_takencancelIdleCollectingDispensingAll 3 states are reachable and every transition names states that exist.INFONo state is marked `final`, so this machine never terminates. That is ordinary for a reactive controller and a smell for a workflow.OKAll 3 states are reachable from `Idle`.OKAll 5 transitions name states that exist, so every arrow in the figure is drawn.

Make it your own.

title "Vending machine"
state Idle
state Collecting
state Dispensing
initial Idle
transition Idle -> Collecting on "insert_coin"
transition Collecting -> Collecting on "insert_coin"
transition Collecting -> Dispensing on "enough_paid"
transition Dispensing -> Idle on "item_taken"
transition Collecting -> Idle on "cancel"