Firmware flow
Preparing power-down and restoring operation after wake
Selected AVR sleep helper and its pin-change handler; the vibration interrupt source is configured separately during setup.
The helper clears the event flag, disables the ADC and requests power-down sleep. The pin-change handler marks the wake event. After execution resumes, the helper disables sleep and restores the ADC; lighting restoration belongs to the main loop.
The source shows the intended sleep and wake sequence. Current draw, battery life, wake latency and hardware reliability have not been measured in this review.
Read the implementation
Selected firmware excerpt. The diagram explains the code; it is not a hardware test.
Selected implementation
void enterPowerDownUntilVibration() {
wokeFromPCINT = false;
// Disable ADC to save power
ADCSRA &= ~(1 << ADEN);
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
cli();
sleep_enable();
#if defined(BODS) && defined(BODSE)
// Disable Brown-Out during sleep (saves more power)
sleep_bod_disable();
#endif
sei();
sleep_cpu(); // ---- CPU sleeps here ----
// Woke up
sleep_disable();
ADCSRA |= (1 << ADEN);
}
// ---------- ISRs ----------
ISR(PCINT0_vect) { // PORT A pin-change
wokeFromPCINT = true;
}Technical notes
Saved lighting settings
The firmware offers 20 colour entries and 15 brightness levels. Button events update the selected setting, save it to EEPROM and reapply the RGB PWM output; startup restores the saved values with range checks.
An inactivity threshold
Button presses and vibration-switch activity refresh the activity timer. At the configured three-second inactivity threshold, the main loop turns the RGB outputs off, marks the lighting inactive and calls the power-down helper.
Wake flag, then lighting restore
The vibration pin-change handler sets a wake flag. After the CPU resumes, the sleep helper disables sleep and restores the ADC; the next main-loop iteration uses the flag to restore lighting. The source shows this intended sequence, without establishing measured battery life, current draw or wake latency.