stationeers.de Mod workshop · Dominik1199
DE Sign in
  1. Home
  2. IC10 academy
  3. Day 132

Day 132 of 365 · Advanced · Month 5: Memory and structure

Project: multi-room controller

Project of the week: a single subroutine controls three rooms. It gets the room name in a register and remembers its heating state in the stack.

Project 40 min Week 19

What you learn today

  • One subroutine for all rooms
  • Pass names via registers
  • Save lines

Lab, kitchen, store: three rooms, three times the same hysteresis. Copied, that makes three times eight lines and three chances to copy a limit wrongly. With a subroutine the rule exists once, and the rooms call it one after another.

The setup

Roomgas sensorwall heaterstack slot
labLaborLabor0
kitchenKuecheKueche1
storeLagerLager2

Sensor and heater of a room carry the same name, the type tells them apart. In addition there is a flashing light “Heizstoerung” as a collective alarm.

Passing names via registers

lbn and sbn also take the name hash from a register. So the subroutine gets the room in name:

move name LAB
move nr 0
jal room

Inside the subroutine it then says lbn temp SENSOR name Temperature Average and sbn HEATER name On heat. Which room is meant is decided solely by the content of name.

Remembering the state per room

A hysteresis needs a memory. One register for all three rooms is not enough, so every room gets a slot in the stack, its number is in nr:

room:
get heat db nr          # fetch this room's state
# ... hysteresis ...
put db nr heat          # and write it back
sbn HEATER name On heat
j ra

Milestones

  1. Lab heats with hysteresis: on below 19 °C, off from 21 °C, keep the state in between.
  2. Three rooms independent: every room controls by its own sensor without disturbing the others.
  3. One sensor fails: only its heater goes off, the collective alarm lights up.
  4. Everything fine: if all sensors are there, the collective alarm is off.
Tip

A fourth room only costs three lines in the main loop and one define. That is the whole point: saving lines and characters without losing clarity.

Warning

In the game the stack survives an upload. An old heating state at slots 0 to 2 is harmless, because the hysteresis corrects it in the next tick. But if you use the slots for something else, tidy them up with poke before the start label.

Diagram

Calling and returning from a subroutine Main loop 2 l r0 d0 Temperature 3 jal celsius 4 s d2 Setting r1 5 l r0 d1 Temperature 6 jal celsius 7 s d3 Setting r1 8 j start celsius: sub r1 r0 273.15 j ra ra = 4 back to line ra
Three times the same call, each time with a different name and a different stack slot. The code for one room exists only once.

Project task

Task

Build the multi-room controller with one subroutine room that gets the name in name and the stack slot in nr. Rooms, names and slots are in the table. The collective alarm “Heizstoerung” lights up as soon as a sensor is missing. The milestones are listed above the editor.

Milestones

  1. Milestone 1: lab heats with hysteresis
  2. Milestone 2: three rooms independent
  3. Milestone 3: one sensor fails
  4. Milestone 4: everything fine, no alarm

Hints

Hint 1

Per room three lines in the main loop: move name …, move nr …, jal room.

Hint 2

In the subroutine: fetch the state with get heat db nr, hysteresis, back with put db nr heat.

Hint 3

Count missing sensors in the subroutine with snan into faults, switch the lamp afterwards with sgtz.

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

Esc
↑ ↓ selectEnter open/ opens search anywhere