Raspberry Pi practice problem · LEDs & PWM
BCD counter
HardBudget $12Python · gpiozero
Binary-coded decimal (BCD) gives each decimal digit its own 4 bits — it's how many clocks and meters drive their digits.
Eight LEDs:
- tens digit: bit 0 GPIO5, bit 1 GPIO6, bit 2 GPIO13, bit 3 GPIO19
- units digit: bit 0 GPIO12, bit 1 GPIO16, bit 2 GPIO20, bit 3 GPIO21
Count 00, 01, … 99 with one step every 0.1 s (00 at 0 s, 42 at 4.2 s, 99 at 9.9 s), then wrap to 00 at 10.0 s and keep counting.
So 42 is tens 0100, units 0010; 10 is tens 0001, units 0000 (not binary 1010!).
Tip: divmod(n, 10). To stay on time over 100 steps, base each step on the start time rather than adding up sleeps.