What you learn today
- Feed several displays
- round values
- Choose units
Four displays above the door to the engine room: generation, consumption, balance, battery level. One glance and you know whether the night will last. For that to work, every display has to show the right unit and not seven decimal places.
DisplayMode picks the unit
The LED display formats Setting depending on Mode. The most important ones for power:
| Mode | Name | shows |
|---|---|---|
| 0 | DisplayMode.Default | the bare number |
| 1 | DisplayMode.Percent | Setting · 100 with % – so write the share from 0 to 1 |
| 2 | DisplayMode.Power | watts with a prefix: 1500 becomes 1.5 kW |
| 7, 8 | DisplayMode.Seconds, DisplayMode.Minutes | time with unit |
The display does not convert the unit. DisplayMode.Celsius only appends “°C” – you have to write Celsius into it yourself, not Kelvin. And in percent mode a Ratio of 0.73 is exactly right, 73 would be 7300 %.
sbn DISP HASH("Erzeugung") Mode DisplayMode.Power
sbn DISP HASH("Akkustand") Mode DisplayMode.Percent
Feeding several displays
Every display gets its own name and its own sbn. You simply write the Mode along every tick – it costs one line and survives somebody fiddling with the device. If several displays need the same value, give them the same name: one sbn then reaches all of them.
Rounding values
round rounds to whole numbers. For digits after the point you shift the point: multiply first, round, divide again.
mul level level PLACES
round level level
div level level PLACES
With PLACES 100 0.7341 becomes exactly 0.73 – “73 %” in percent mode. For power values round alone is enough: 1799.8 W becomes 1800 W.
Calculate first, then round. If you round generation and consumption and subtract afterwards, the balance stays whole and matches the two displays above it exactly – that saves questions like “why is 3000 − 1800 not 1200?”.
If the analyzer is missing, the three power displays show −1 and the balance turns red. A display showing NaN looks broken. One showing −1 says: “reading missing”.
Exercise
Task
Feed four displays: “Erzeugung” (PowerPotential), “Verbrauch” (PowerRequired) and “Bilanz” (generation − consumption) in mode DisplayMode.Power, rounded to whole watts. “Akkustand” shows the average Ratio of the batteries “Akku” in mode DisplayMode.Percent, rounded to whole percent. The balance is green as long as it is not negative, otherwise red. If the analyzer “Hauptnetz” is missing: the three power displays −1, balance red.
Hints
Hint 1
First the four Mode lines with DisplayMode.Power and DisplayMode.Percent.
Hint 2
round for both power values, then sub balance gen use, afterwards one select … ok … -1 each.
Hint 3
Colour: sltz colour balance, then select colour colour Color.Red Color.Green. Battery: times 100, round, divide by 100.
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