TactivergeLite

Lite / Discovering How the World Works / Week 17

Machines that remember: states and sequences

A traffic light is green. What colour comes next? The light itself has to remember where it is in the cycle. How?

About 30 min · 3 goals · Reviewed by the founders' mentors · Full interactive version

Why should I care?

Many machines can't decide from the sensors alone: a washing machine must know whether it's washing or spinning; a traffic light must know whether it was just green. A state machine is the simple, powerful idea engineers use to give machines that memory.

Predict

A traffic light shows amber. In the UK it could be heading towards red or towards green. What does the controller need to decide correctly?

  1. A brighter bulb
  2. To remember which state it was in before
  3. A faster clock
Guess first, then reveal

It needs to remember its state. Amber after green means 'red next'; red-and-amber together means 'green next'. The current light alone isn't always enough, so the controller stores which step of the cycle it's in.

Discover

In the Traffic System Build, Level 1, judge each moment at the crossroads as safe or a conflict. Then say what each light must show next. Which moments are unsafe, and what rule would stop them?

What the interactive shows (text version)

The Traffic System Build's Level 1 shows six moments at a crossroads with traffic lights and a pedestrian crossing. Moments where two conflicting movements both have a go signal (for example, north–south amber while east–west is green, or walk while north–south is green) are conflicts. You also choose what the lights should show next at three points in the cycle.

You can also open the interactive on the full site when you have a faster connection.

Understand

A state is 'where I am'

A state is the machine's current situation: green, amber, red; or filling, washing, spinning. The machine is always in exactly one state, and it remembers it until something makes it move on.

Transitions: the rules for moving on

A transition is a rule like: 'in GREEN, after 30 seconds, go to AMBER'. Transitions can be triggered by time, by a sensor ('button pressed') or both. Draw states as circles and transitions as labelled arrows, and you have a state diagram.

Designing out danger

Some combinations must never happen: north–south green while east–west is green is a crash. Engineers list these unsafe states and design the transitions so they can't be reached, adding an all-red pause between greens for safety. A state machine is easy to check because it has a short, complete list of states.

Explain it another way

Intuitive

A board game piece on a track is a state machine: where you are is your state; the dice and the squares' rules decide your transition. You need to remember your square, or you can't take your next turn.

Technical

A finite state machine has a finite set of states, an initial state, inputs and a transition function: next state = f(current state, input). Storing the current state needs memory: with 8 states, 3 bits.

Applied

Lifts, vending machines, washing machines, game characters and robot behaviours (search → approach → grab → return) are all built as state machines. Safety engineers audit every transition.

Worked example 1

A simple pedestrian crossing has states: CARS GO, CARS STOP (amber), WALK, FLASHING. Write the transitions.

CARS GO → (button pressed and 20 s passed) → CARS STOP → (3 s) → WALK → (7 s) → FLASHING → (10 s) → CARS GO. The button only matters in CARS GO; pressing it during WALK changes nothing.

Common mix-ups

Practice

Practice, not a test. Answers are checked on our server; a wrong answer gets a hint and another try. Nothing is saved.

Practice 1. Which of these is a STATE of a washing machine?

bits

Practice 3. At a crossroads, which state must never be reachable?

s

Apply it

Draw a state diagram for a microwave: IDLE, COOKING, PAUSED (door opened), DONE. Label every transition with what triggers it. Which transition is a safety rule?

Reflect

Name a machine you use that must remember something to work properly. What is it remembering?

Write your answer on paper or in your own notes. Lite never stores what you write.

← Flowcharts: drawing a decisionPlan your machine: from problem to design →