What you learn today
- Switch a heater by temperature
- Show the state in colour
- Set the target via the housing
Your habitat module should stay warm, and you want to change the target without touching the code. Everything you need you know from this week and the previous ones: set instructions, select, min, max and round.
The setup
| Pin | Device |
|---|---|
d0 | gas sensor in the room |
d1 | wall heater |
d2 | LED display |
db | housing: target in °C |
The target in the housing
The program reads the target from db Setting, in degrees Celsius. In the game it later comes from another device or chip, in the simulator you set it by hand. Two safeguards belong to it:
- If the housing still holds 0, 20 °C applies. That way a freshly inserted chip does not cool the room down to 0 °C.
- The target is limited to 5 to 35 °C. A typo like 300 does not turn the module into a sauna.
l r1 db Setting # target in C
seqz r2 r1 # 1 = nothing entered
select r1 r2 20 r1 # then 20 C
max r1 r1 5
min r1 r1 35
Heating and colour
The heater runs when it is more than 1 °C colder than the target. A real hysteresis with memory comes in week 7, today the band from week 4 is enough.
The display shows the temperature in °C with one decimal, mode Celsius, and takes on a colour:
| State | Colour |
|---|---|
| heater running | blue (0) |
| more than 1 °C too warm | red (4) |
| otherwise | green (2) |
Two select in a row do that. The second overwrites the first when the heater is running:
select r6 r5 4 2 # red or green
select r6 r4 0 r6 # blue while heating
Milestones
- Cold: heater on.
- Warm enough: heater off, display green.
- Display in °C with one decimal, mode Celsius.
- Blue while heating, red when too warm.
- Without a target 20 °C applies.
- Target limited to 5 to 35 °C.
Convert to Celsius early and compare in Celsius – the target in the housing is in Celsius too. Never compare Kelvin with Celsius.
Diagram
Project task
Task
Build the thermostat from the lesson, without conditional jumps (only j start):
- Target in °C from
db Setting; 0 means 20 °C; limited to 5 to 35 °C. - Heater
d1on when the temperature is more than 1 °C below the target. - Display
d2: temperature in °C, one decimal, Mode 4. - Colour: blue (0) while heating, red (4) when more than 1 °C too warm, otherwise green (2).
Milestones
- Milestone 1: cold – heater on
- Milestone 2: warm enough – heater off, green
- Milestone 3: display in °C with one decimal
- Milestone 4: blue while heating, red when too warm
- Milestone 5: without a target 20 °C applies
- Milestone 6: target limited to 5 to 35 °C
Hints
Hint 1
Fallback: seqz r2 r1, then select r1 r2 20 r1.
Hint 2
Deviation r3 = actual − target. Heater: add r4 r3 1 and sltz r4 r4.
Hint 3
Colour with two select, display with times 10, round, divided by 10.
Quiz
2 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed all milestones of the project
- Passed the quiz with at least 60 %
Without an account progress is saved in this browser only.
Report a mistake in this lesson
Please sign in to report. Sign in