Traffic light

A clock, a counter, and a decoder cycle three lamps like a street-corner signal. A ready-made fun circuit you can open in the TorchAnvil simulator.

A tiny finite-state machine

A real traffic controller is, under all the weatherproofing, a little state machine: something counts, something decodes the count into "which lamp is on," and a clock keeps it marching. This sample builds the smallest honest version of that. A 2-bit counter cycles through four states; a decoder turns each state into a single lamp; an OR stitches two of the states together so red gets two slots in the cycle.

How it works

The counter is two T flip-flops in the familiar ripple pattern:

Then a tiny 2-to-4 decoder turns that count into four state lines Y0…Y3, one per combination of C1 and C0:

Finally the outputs:

tick C1 C0 state lit
0 0 0 Y0 Red
1 0 1 Y1 Green
2 1 0 Y2 Yellow
3 1 1 Y3 Red
4 0 0 Y0 Red (wrap)

Why it matters

Counter plus decoder plus output logic is the template for basically every hardware sequencer you'll ever meet. Washing machines, elevator dispatchers, arcade-cabinet attract-mode animations, even the microcode ROMs inside old CPUs — they all boil down to "advance a counter, look up what to do this tick." Once you've built one, you've built them all.

Try this