B07BAR GRAPH
The task
P0 is an analog input: IN P0 reads its voltage as a percent of the 5 volt supply.
Light an LED for each quarter of the supply the input reaches:
P1 from 25 percent, P2 from 50, and P3 from 75.
Sample the input on each tick of P4.
The board
- Sources
- V1 2.5 V and V2 2.5 V triangle at 50 Hz
- Resistors
- R1 330 Ω, R2 330 Ω, and R3 330 Ω
- LEDs
- D1 green, D2 yellow, and D3 red
- Probes
- CH1, CH2, CH3, and CH4
Key idea
DIV 25 turns the reading into the number of quarters it has reached.
Hints
Each hint goes a step further than the one before. Open them one at a time.
Hint 1Show
A digital output is on for any value but 0, so a quotient of 1 or more lights an LED.
Hint 2Show
CH1 is the input; CH2 to CH4 are the LEDs.
Solution
Reveal the Full SolutionThe complete program for BAR GRAPH. 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.
u1SC-2 standard
IN P4
IN P0
MOV B, A
DIV 25
OUT P1
MOV A, B
DIV 50
OUT P2
MOV A, B
DIV 75
OUT P3- CYCLES
- 210
- at par
- ENERGY
- 420
- at par
- NODES
- 1
- at par
- INSTRUCTIONS
- 11
- at par
Another way: Quarters
A second program that also passes, and beats par on CYCLES, ENERGY, and INSTRUCTIONS.
One division: the quarters, then halves and thirds of the quarters.
u1SC-2 standard
IN P4
IN P0
DIV 25
OUT P1
MOV B, A
DIV 2
OUT P2
MOV A, B
DIV 3
OUT P3- CYCLES
- 191
- under par
- ENERGY
- 382
- under par
- NODES
- 1
- at par
- INSTRUCTIONS
- 10
- under par