What you learn today
- Several names for several rooms
- Process values one after another
- Save lines
Three rooms, three sensors, three heaters. Three chips would work, but every chip costs a housing, power and care. One chip is enough – if the names are well planned.
Same name, different type
lbn and sbn filter by type and name. That is why sensor and heater in the lab may both be called “Labor”: the type hash decides which device is meant. That saves names and keeps the base tidy – every device carries the name of its room.
lbn temp SENSOR HASH("Labor") Temperature Average
sbn HEATER HASH("Labor") On on
The simple way: block by block
The same three lines for every room, just with a different name. That is easy to read but costs three lines and a good 150 characters per room. With five rooms and a display per room it gets tight.
The name in a register
HASH("Labor") is already a number when the code loads. That number may sit in a register too, and lbn/sbn take it from there:
move room HASH("Lager")
lbn temp SENSOR room Temperature Average
sbn HEATER room On on
That way you write the control part only once and swap the name beforehand.
One room per tick
A counter picks the next room every tick: 0, 1, 2, 0, 1, 2 … With seq and select that becomes the name:
add nr nr 1
mod nr nr ROOMS # 0, 1, 2, 0 ...
move room HASH("Labor") # room 0
seq tmp nr 1
select room tmp HASH("Lager") room
seq tmp nr 2
select room tmp HASH("Wohnen") room
Every room gets its turn every three ticks, so every one and a half seconds. For heaters that is more than fast enough.
A room without a working sensor returns NaN. slt then gives 0, that room's heater switches off. The other rooms do not notice, because each has its own tick.
Plan the names before you pick up the labeller: one short name per room, no special characters. For devices that belong to no room, use names of their own such as “Hauptschalter”.
Diagram
Exercise
Task
Frost guard for three rooms with one chip. Each room has a gas sensor and a wall heater named after the room: “Labor”, “Lager”, “Wohnen”.
- A room's heater on when it is below 19 °C (292.15 K) there, otherwise off.
- Write the control part only once: room name into a register, one room per tick.
- If a sensor fails, only that room's heater switches off.
Hints
Hint 1
Counter: add nr nr 1, then mod nr nr ROOMS.
Hint 2
Name: first move room HASH("Labor"), then seq and select twice.
Hint 3
Control part with room instead of HASH(…): lbn temp SENSOR room Temperature Average.
Quiz
4 questions. You pass from 60 % – the server does the grading.
Complete the day
- Passed the simulator exercise
- 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