What you learn today
- Read levers and switches
- Detect a button press via Activate
- Switch lights
A chip that only measures is deaf. By the time you get to the hallway light you want a say yourself. That is what levers, switches and buttons are for. They need no power and only hang on the data network.
Levers and switches: Open
Lever (StructureLogicSwitch) and switch (StructureLogicSwitch2) report their position in Open: 1 means flipped, 0 means not flipped.
l r0 d0 Open # lever flipped?
s d1 On r0 # light follows the lever
If you need the opposite, such as an emergency light that is on as long as the lever is not flipped, compute 1 − Open:
sub r1 1 r0 # 1 becomes 0, 0 becomes 1
s d2 On r1
s d0 Lock 1 locks a lever. Then nobody can flip it by hand any more – handy for switches only the chip should operate.
Lights: On
Wall light (StructureWallLight), flashing light (StructureFlashingLight) and the round lights are switched with On. Whether they really get power is told by Power: 1 means supplied. A light with On = 1 and Power = 0 stays dark.
Buttons: Activate
The button (StructureLogicButton) works differently. When you press it, Activate jumps to 1 – but only for a little over half a second, then the value drops back to 0 on its own. While it is still 1, the button cannot be pressed again.
l r2 d3 Activate # 1 only at the moment someone presses
Half a second is about one tick. A program that runs only once misses almost every button press. Only with the main loop from week 3 does the chip read the button every tick and catch it reliably.
What you can build now
With lever, light and the math instructions you can already build small circuits: light on, emergency light off, display at 1. Every program still runs only once. If you flip the lever after the chip is done, nothing happens – that changes in week 3.
Exercise
Task
A lever is attached to d0, the hallway light to d1 and an emergency light to d2.
- The hallway light is on when the lever is flipped.
- The emergency light is on exactly when the lever is not flipped.
Hints
Hint 1
The lever's position is in Open.
Hint 2
The opposite of 0/1: sub r1 1 r0.
Quiz
5 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