What you learn today
- Several greenhouses
- Collective alarm
- Harvest status
The farm is growing: next to “GH1” there is now “GH2”. A second chip with almost the same code would be twice the upkeep. Better is a subroutine that handles one greenhouse and is called twice – with the name in a register.
The setup
| Device | Prefab | Names |
|---|---|---|
| Gas sensors | StructureGasSensor | “GH1”, “GH2” |
| Wall heaters | StructureWallHeater | “GH1”, “GH2” |
| Hydroponics devices | StructureHydroponicsTrayData | 3 × “GH1”, 2 × “GH2” |
| Wall light | StructureWallLight | “Sammelalarm” |
| LED displays | StructureConsoleLED5 | “Alarm”, “Reif” |
The subroutine
Before each jal house the main program sets three registers: name (hash of the house name), num (trays in the house) and bit (1 for GH1, 2 for GH2). The subroutine then does this for that house:
- Heater with hysteresis, 20 to 24 °C. It simply reads the previous state back from the heater (
lbn heat HEATER name On Average) – that way no house needs a register of its own. - Alarm below 15 °C, above 35 °C or with a missing sensor. An alarm adds
bitto the sum: GH1 alone gives 1, GH2 alone 2, both 3. - Count ripe plants. Empty trays return
Mature−1. WithSumtherefore: ripe = sum ofMature+ trays − sum ofOccupied.
Milestones
- Each house has its own heater with hysteresis.
- The display “Alarm” shows 0, 1, 2 or 3, the light “Sammelalarm” is on for any alarm.
- The display “Reif” shows the ripe plants of both houses together.
- If a sensor fails, there is an alarm for that house and its heater goes off.
The calculation for ripe plants is not obvious. Work it out once by hand for GH1: ripe 1, growing 0, empty −1 gives a sum of 0, 2 of 3 trays are planted, so 0 + 3 − 2 = 1 ripe plant.
A third house only needs three more move and one more jal – and a new alarm value of 4, not 3. Otherwise you cannot tell “GH3” from “GH1 and GH2”.
Diagram
Project task
Task
Build the farm control with a subroutine house that handles heater, alarm and ripe plants for the house in name. GH1 has 3 trays and alarm value 1, GH2 has 2 trays and alarm value 2.
Milestones
- Milestone 1: heater per house
- Milestone 2: collective alarm
- Milestone 3: harvest status
- Milestone 4: sensor fails
Hints
Hint 1
Main program: alarm and ripe to 0, then twice move name …, move num …, move bit …, jal house.
Hint 2
In the subroutine lbn temp SENSOR name Temperature Average – the name comes from the register.
Hint 3
Ripe: add lbns … Mature Sum, add num, subtract lbns … Occupied Sum. At the end j ra.
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