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

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

Project: light scenes

One button steps through four light scenes, the light groups switch on and off one after another, and on emergency power the emergency light flickers via rand.

Project 35 min Week 21

What you learn today

  • Scenes via button
  • Smooth dimming
  • Random flicker for emergency lighting

The workshop has four rows of lights. During the day everything should be bright, dimmed in the evening, only one row at night. When the emergency power runs, only a flickering emergency light remains. The whole thing is operated with a single button.

The plant

DevicePrefabName
ButtonStructureLogicButton“Szene”
LeverStructureLogicSwitch“Notstrom”
four light groupsStructureWallLight“Licht1” to “Licht4”
LED displayStructureConsoleLED5“Szene”

The scenes

No.SceneGroups on
0Offnone
1Work1 to 4
2Evening1 and 2
3Night1

Every press of the button moves on one scene, after 3 comes 0 again. The table sits in the stack via poke before the main loop, get target db scene fetches the number of groups.

The button reports Activate = 1 as long as it is held down. So that a long press does not step on every tick, only the edge counts – the change from 0 to 1:

sgt tmp button last   # 1 only in the first tick of the press
move last button
add scene scene tmp
mod scene scene SCENES

Smooth dimming – with honest lights

In the game lights only know On, there is no dimmable light. So “smooth” means here: the groups switch on or off one after another, one per second. A level from 0 to 4 runs towards the scene’s target, group k is lit as long as the level is at least k:

sub tmp target level
sgn tmp tmp           # -1, 0 or 1
add level level tmp   # one step towards the target
sge lit level 3       # group 3 on from level 3

A counter makes sure the level only takes a step every TICKS ticks. It may keep running when the level has already reached the target: the difference is 0 then, and sgn returns 0.

Emergency light

When the lever “Notstrom” is at 1, groups 2 to 4 go off. Group 1 flickers: every tick rand decides whether it is lit, with a probability of 70 %. Put the lever back and the scene returns.

Milestones

  1. Scenes via the button, on the edge only, the display shows the number
  2. Smooth dimming: one group after the other, up and down
  3. Emergency light: group 1 flickers, groups 2 to 4 are off
  4. Failure: without the lever normal operation applies; without the button the scene stays
Warning

Button and lever return NaN when they are missing. A NaN button must neither trigger an edge nor poison last. sgtz button button turns NaN into a clean 0 – the same for the lever. After that both values can safely go into and, sgt and select.

Project task

Task

Build the light control following the rules above. The defines, the scene table in the stack and the start label are already there; sections 2 to 6 are missing: button with edge, smooth dimming, reading the emergency power, group 1 and groups 2 to 4.

Milestones

  1. Milestone 1: scenes via button, on the edge only
  2. Milestone 2: dim smoothly, up and down
  3. Milestone 3: emergency light flickers
  4. Milestone 4: lever or button fails

Hints

Hint 1

Edge: sgtz button button, then sgt tmp button last and move last button. Step on with add and mod.

Hint 2

Dimming: add time time 1, blt time TICKS lights, then move time 0 and one step towards target with sub, sgn, add.

Hint 3

Group k: sge lit level k. For group 1 select lit emerg tmp lit picks the flicker, for 2 to 4 and lit lit normal helps.

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