Crack the Code · follow the program

One request. Seven states.

Watch the lights, follow the timer, see why the code moves on.

15 secondsfrom request to ready
Crossing signalsReady

Vehicles

D4
D5
D6

Pedestrians

WAITD13
WALKD8

The program remembers

phase = READY

Time in this state0.0 s
Until the next state—
CURRENT TRANSITION CHECK

Press Request crossing, or inspect a state below.

Select any state or drag the timeline to inspect it. Each new state starts its own elapsed timer at zero.

How the timer and outputs work

phase and started survive between loop passes. now and elapsed are calculated again each pass. The timer checks time without pausing the program.

void enter(Phase next, unsigned long now) {
  phase = next; started = now;
}

&& requires both conditions to be true. The else if chain allows one timed transition per pass. Afterwards, elapsed is recalculated and the outputs use the new phase.

Vehicle red · D4
Vehicle yellow · D5
Vehicle green · D6
WALK · D8
Request · D12
WAIT · D13

The shield’s D8, D12 and D13 LEDs represent these pedestrian signals. Green is on only in READY and REQUESTED; WALK is on only in WALK. They never overlap.

The input must stay stable for 25 ms before it is accepted. Holding the button does not create another press. During CLEARANCE, WAIT changes every 250 ms: a full flash takes 500 ms.

Try a prediction

Then inspect WALK and press the request button again. Explain which condition prevents the sequence from restarting.