2022-02-15
Part of my journey through Shenzhen I/O
Problem: There are five simple I/O outputs to drive a deterministic animation on a sign of a gamer drinking and playing games. In total, there are five outputs: 2 to drive the "clicking" animation for gaming, and 3 to drive the "drinking" animation.
First Attempt
I used four separate MC4000s in this attempt. One drives the two "click" outputs, and the other three drive one each of the "drink" outputs.
For the "click" driver, the code is quite short, since the two click animations are simply the inverse of one another:
mov acc p1
not
mov acc p0
slp 1
The three code blocks to drive drink-0
, drink-1
and drink-2
are more involved:
drink-0
mov 100 p0
slp 6
mov 0 p0
slp 4
drink-1
slp 6
mov 100 p0
slp 1
mov 0 p0
slp 2
mov 100 p0
slp 1
mov 0 p0
drink-2
slp 7
loop:
mov 100 p0
slp 2
mov 0 p0
slp 8
jmp loop
This leaves cost at ¥12, uses 22 lines of code and consumes 255 power, which isn't very good.
Second Attempt
One insight is that drink-1
is a not or
operation on drink-0
and drink-2
. This is useful because it requires two cycles per pass through the code instead of one.
I wasn't able to leverage this in this run, though. I instead found that I could combine drink-0
and drink-2
into a single MC4000 (9 lines of code), reducing cost and power. The "click" animation and drink-1
are identical to the first attempt.
drink-0 and drink-2
mov 100 p0
slp 6
mov 0 p0
slp 1
mov 100 p1
slp 2
mov 0 p1
slp 1
This reduces cost to ¥9, lines of code to 20, and power to 251. This is average for cost, slightly better than average for lines of code, and slightly worse than average for power.