The programs so far ran once and were done. For a controller that is useless: the temperature keeps changing, so the chip has to measure again and again.
When the chip runs off the end
When the chip reaches the end of the program, it stops for good – no error, no light. It does not restart on its own either. Only pulling the chip and putting it back in wakes it up. That is why every real program ends with a jump back to the start:
start:
yield
l r0 d0 Temperature
sub r0 r0 273.15
s d1 Setting r0
j start
start: is a label, a jump target. j start jumps there. More about labels in the next lesson.
Ticks and yield
The game computes in ticks of 0.5 seconds. Per tick the chip runs at most 128 instructions, then it waits for the next tick. Device values only change between ticks.
yield says: “I am done for this tick.” Without yield the loop spins for 128 instructions and keeps reading the same value – nothing visible breaks, but it is pointless and makes programs hard to predict.
Rule of thumb: put a yield right after the start label. Then the loop runs exactly once per tick.
sleep
sleep 5 waits five seconds (not ticks) and replaces the yield. Handy for blinking lights or slow sequences.
Diagram
Exercise
Task
Turn the temperature display into a continuous controller: the display on d1 should show the temperature of the sensor on d0 in °C – all the time, even when the value changes. Build an endless loop with yield.
Hints
Hint 1
Put a label above the first instruction, e.g. start: – alone on its line.
Hint 2
Below it yield, at the very end j start.