Simple vending machine circuit
Without getting into the specific binary coding of inputs, outputs and states, the abstract state diagram should look something like this. The notation on each edge is Input&rarr;Output.



Note that I have defined a third output "Refund" that refunds the coins inserted so far, which is a distinct operation from dispensing change along with a snack if 25 cents have been inserted.

Note that most real vending machines hold the coins that the user has inserted in a separate area until a snack has been dispensed, at which time, they are released into the actual coin box. If a refund is requested instead, the user gets his original coins back.