Syscall 2: Firmware, home

BenchChapter 12: Shared buses

B92PORCH LIGHT

The task

P0 reads a motion sensor on CH1 and P1 the daylight on CH2. Sample both on each tick of P3.

While the daylight reads under 30, motion lights the lamp on P2.

The lamp stays lit until 4 ticks pass without motion in the dark.

The board

The chip of PORCH LIGHTChip u1 with 4 ports: P0 digital in, reaching V1, CH1; P1 analog in, reaching V3, CH2; P2 digital out, reaching R1, D1, CH3; P3 timer 20 cycles.u1CHIP SC-2P0DIGITAL INV1, CH1P1ANALOG INV3, CH2P2DIGITAL OUTR1, D1, CH3P3TIMER 20 CYCLES
The chip's ports, each with its kind and the parts its signal reaches. Cyan reads, lemon writes. On a narrow screen, scroll the board sideways to see all of it.
Sources
V1 1 V square at 16.67 Hz, V2 2.5 V square at 125 Hz, V3 2 V sine at 4 Hz, and V4 2.5 V
Resistors
R1 330 Ω
LEDs
D1 yellow
Probes
CH1, CH2, and CH3

Key idea

This is RETRIGGER with a condition: only dark motion sets the count to 4.

Hints

Each hint goes a step further than the one before. Open them one at a time.

Hint 1Show

Check the daylight first; in daylight, treat the tick as one without motion.

Hint 2Show

Every tick without dark motion counts B down, and the lamp goes out at zero.

Solution

Reveal the Full SolutionThe complete program for PORCH LIGHT. Open it only when you want the answer.

The reference program

The game's own solution. It passes every test and scores exactly par on every benchmark.

A retriggerable hold, armed only in the dark.

u1SC-2 standard

L: IN P3
IN P1
SUB 30
JL DK
DEC: MOV A, B
JZ L
SUB 1
S: MOV B, A
OUT P2
JMP L
DK: IN P0
JZ DEC
MOV A, 4
JMP S
CYCLES
883
at par
ENERGY
1766
at par
NODES
1
at par
INSTRUCTIONS
14
at par