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

Day 16 of 365 · Beginner · Month 1: First steps

sleep and time

sleep waits seconds instead of ticks. How to build delays with it, why sleep never belongs on line 0 and when a counter is better.

Lesson 9 min Week 3

What you learn today

  • sleep in seconds instead of ticks
  • Build delays
  • No sleep on line 0

After the pressure equalises, the light above the door should only come on after three seconds. With yield you would have to count six ticks for that. sleep makes it easier.

sleep counts seconds

sleep 3 pauses the chip for three seconds, not three ticks. At 0.5 s per tick that is six ticks. After that it continues on the next line. A register works instead of a number too: sleep r5.

# light three seconds after start
s d0 On 0
sleep 3
s d0 On 1

Inside a loop sleep also replaces the yield. A reading every five seconds looks like this:

# pressure to the display every 5 seconds
start:
l r0 d1 Pressure
s d2 Setting r0
sleep 5
j start

Since October 2024 sleep uses game time. If you pause the game, the waiting time pauses too.

The line 0 trap

Warning

sleep must not be on line 0. Internally the chip remembers where it waits as a negative line number – and −0 is the same as 0. On line 0 it therefore does not notice that it is waiting and burns all 128 instructions every tick. A comment or label before it is enough.

sleep makes the chip deaf

During sleep the chip reads nothing and switches nothing. A button press in that time is lost, a pressure drop goes unnoticed for five seconds. For displays and slow sequences that is fine. For anything that has to react quickly you use yield and count the ticks yourself – that comes the day after tomorrow.

Instructionwaitschip reacts meanwhile
yieldone tick (0.5 s)again in the next tick
sleep 2two seconds (4 ticks)no
tick counteras long as you likeyes, every tick

Diagram

Ticks and yield on a timeline tick 0 · 0.0 s tick 1 · 0.5 s tick 2 · 1.0 s tick 3 · 1.5 s 5 instr. yield 5 instr. yield 5 instr. yield 128 instr. no yield: limit hit Device values only change between two ticks.
At most 128 instructions run per tick. yield ends one tick, sleep skips several at once.

Exercise

Task

A gas sensor is attached to d0, a light to d1, an LED display to d2.

  1. At start the light is off.
  2. After 3 seconds it comes on and stays on.
  3. After that the display shows the current pressure every 2 seconds.

Use sleep – and mind line 0.

Hints

Hint 1

First s d1 On 0, then sleep 3, then s d1 On 1.

Hint 2

The loop below: read, display, sleep 2, j start.

Hint 3

The comment on line 0 makes sure no sleep ends up there.

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

Esc
↑ ↓ selectEnter open/ opens search anywhere