// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // checks the state of the button void checkButton(eventState_t state) { // ignore any button presses after waking up if (_wakingUp) return; // check switch pin if ((SWITCH_PINS & (1<<SWITCH_PIN)) != 0) { // enable switch interrupt SWITCH_PCMSK |= (1<<SWITCH_PCINT); return; } // shutdown the CPU and all effects sfx_off(); // shutoff the LEDs dbg_led_off(); serial_led_off(); play_led_off(); twi_led_off(); // enable button interrupt which will wake us back up SWITCH_PCMSK |= (1<<SWITCH_PCINT); _wakingUp = 1; switch_en(); // go to sleep sleep_cpu(); // registerOneShot(enableButton, 8000, EVENT_STATE_NONE); // wake back up sfx_on(); }
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - // main func int main(void) { init(); // run as fast as possible registerHighPriorityEvent(ledPWMHandler, 0, 0); // move to the next sleepy-eye value registerEvent(nextSleepyEyeHandler, SAMPLE_RATE / 4, 0); // slide-up/slide-down to current sleepy-eye value registerEvent(slideToSleepyEyeHandler, SAMPLE_RATE / 100, 0); // subscribe to a time-based ACD sampling registerHighPriorityEvent(adcSampleHandler, SAMPLE_RATE / 50, 0); registerOneShot(ampOnHandler, SAMPLE_RATE, 0); // main program loop while(1) { eventsDoEvents(); } }