time is a simple input connected to a clock that provides the current time.
off-time are XBus inputs that specify the time at which the alarm should be enabled and disabled, respectively.
sensor is a simple input that indicates the level of infrared detected.
alarm is a simple output that enables the alarm when
100 is sent to it. If the alarm is enabled and the sensor detects a value of 20 or higher, the alarm should be enabled.
This one was tricky because of the number of inputs. My strategy was to to use a MC6000 to determine whether the system is armed or not.
p1is connected to
timeto provide the current time.
x1is connected to
x2is connected to
x3is connected to the downstream chip that looks at the sensor and triggers the alarm.
To detect whether the system is armed, it stores
acc when the current time matches
on-time, and stores
acc when the current time matches the
off-time. It then moves the value of
x3 for consumption downstream.
teq p1 x1 + mov 100 acc teq p1 x2 + mov 0 acc mov acc x3 slp 1
The logic to trip the alarm reads this value from
x0, and looks at
p0 for the value of
sensor, and outputs the alarm state to
p1, which is connected to
loop: teq x0 100 - mov 0 p1 - slp 1 - jmp loop + tgt p0 19 + mov 100 p1 - mov 0 p1 slp 1
Cost is ¥8, power usage is 481, and 14 lines of code are necessary.