Skip to main content

Subsection 2.7.3 Part 3: Designing State Machines

Now we’ll design two machines that are not the toggle. A single flag gives you two states and no room for a third, while adding a state or an event to a state diagram costs a circle or an arrow. We’ll draw both machines before we write any code, because a machine with a missing arrow is much easier to see on paper than in a switch.

Activity 2.7.2. Drawing a State Diagram.

Before writing any code, draw the state diagram on paper or your table’s whiteboard. Label each state (box), each transition arrow with its triggering event, and each action taken on the transition.

(a)

Draw the state diagram for a 3-state LED cycling FSM: each button press advances to the next LED pattern (pattern A → B → C → A → …). You choose the patterns. How many states do you need? What are the events? What action happens on each transition?

(b)

Draw the state diagram for the Lab 2 pause/resume counter: the counter blinks normally until a button press pauses it; a second press resumes. How is this different from the 3-state cycling FSM?