Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kurt/lowest power sleep with button toggle #26

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 32 additions & 4 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,29 @@
#include <avr/io.h>
#include <avr/interrupt.h> // 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();
Expand Down Expand Up @@ -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;
}
Expand Down