B35TRAFFIC LIGHT
The task
P0, P1, and P2 drive the red, yellow, and green lamps. P3 ticks every 20 cycles.
Light red on the first tick. Red lasts two ticks, then green two ticks, then yellow one,
and around again. Only one lamp is lit at a time.
The board
- Resistors
- R1 330 Ω, R2 330 Ω, and R3 330 Ω
- LEDs
- D1 red, D2 yellow, and D3 green
- Probes
- CH1, CH2, and CH3
Key idea
Each lamp keeps its level until the next OUT on its pin.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
At each change, light the next lamp and put the last one out.
Hint 2Show
IN P3 leaves the tick count in A, and a count is never 0, so it lights a lamp by itself.
Solution
Reveal the Full SolutionThe complete program for TRAFFIC LIGHT. Open it only when you want the answer.
The reference program
The game's own solution. It passes every test and scores exactly par on every benchmark.
Red two ticks, green two, yellow one.
u1SC-2 standard
IN P3
OUT P0
MOV A, 0
OUT P1
IN P3
IN P3
OUT P2
MOV A, 0
OUT P0
IN P3
IN P3
OUT P1
MOV A, 0
OUT P2- CYCLES
- 53
- at par
- ENERGY
- 106
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 14
- at par