What you learn today
- Check all pins
- Show the number of connected devices
- Report a missing device
This week you learned to address devices directly, check whether they are present and pick pins through a register. The project puts it all together: a device scanner for the control cabinet.
The setup
| Pin | Device |
|---|---|
d0 | main sensor (gas sensor) |
d1–d4 | further devices, any kind |
d5 | warning light |
The scanner counts how many of the pins d0 to d4 are in use and writes the number to the housing (db, value Setting). If the main sensor on d0 is missing, the warning light goes on.
Pins in a loop
Instead of writing sdse five times you take the pin from a register. dr2 means: the pin whose number is currently in r2.
move i 0
count:
sdse present dr2 # pin number i in use?
add total total present
add i i 1
blt i PINS count
With dr2 the register number is part of the name, not the alias. Even if i is an alias for r2, the pin is still called dr2. If someone changes the alias, dr2 has to follow.
Milestones
- All five pins in use: the housing shows 5, the warning light is off.
- Two devices are removed: the housing shows 3.
- The main sensor is missing: housing 4, warning light on.
- Everything gone except the warning light: housing 0, warning light on – and no error.
Reset the counter to 0 at the start of every pass. Otherwise the chip keeps counting up every tick.
Diagram
Project task
Task
Count how many of the pins d0 to d4 are in use and write the number as Setting to the housing (db). If the main sensor on d0 is missing, switch on the warning light on d5, otherwise off. The chip must never stop with an error.
Milestones
- Milestone 1: all five pins in use
- Milestone 2: two devices removed
- Milestone 3: main sensor missing
- Milestone 4: only the warning light left
Hints
Hint 1
move count 0 and move i 0 right after the yield.
Hint 2
Inside the loop: sdse present dr2, add up, increase i, jump back with blt i PINS counting.
Hint 3
Afterwards s db Setting count, then sdns for the warning light.
Quiz
3 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