diff --git a/main.cpp b/main.cpp index 190776a7..4dd4827a 100644 --- a/main.cpp +++ b/main.cpp @@ -4,12 +4,29 @@ #include #include // Include this for sei() +volatile bool sleepEnabled = false; // Flag to control sleep mode -int main() -{ +// Interrupt Service Routine for Pin Change Interrupt +ISR(PCINT0_vect) { - while (1) - { +} + +int main() { + // Button setup + DDRB &= ~(1 << PB3); // Set PB3 as input + PORTB |= (1 << PB3); // Enable pull-up resistor on PB3 + + // Configure PB0 as output for the LED + DDRB |= (1 << PB0); // Set PB0 as output + + // Enable Pin Change Interrupt for PB3 + GIMSK |= (1 << PCIE); // Enable Pin Change Interrupts + PCMSK |= (1 << PCINT3); // Enable interrupt for PB3 + + sei(); // Enable global interrupts + + // Turn off LED + PORTB &= ~(1 << PB0); // Disable the Watchdog Timer MCUSR &= ~(1 << WDRF); wdt_disable(); @@ -42,6 +59,17 @@ int main() // Disable sleep mode sleep_disable(); + + while (1) { + + // Re-enable Pin Change Interrupt for PB3 + GIMSK |= (1 << PCIE); // Enable Pin Change Interrupts + PCMSK |= (1 << PCINT3); // Enable interrupt for PB3 + + // Reconfigure PB0 as output for the LED + DDRB |= (1 << PB0); // Set PB0 as output + // Set PB0 (LED) to high when not sleeping + PORTB |= (1 << PB0); } return 0; }