MCUdude / MightyCore

Arduino hardware package for ATmega1284, ATmega644, ATmega324, ATmega324PB, ATmega164, ATmega32, ATmega16 and ATmega8535
Other
637 stars 181 forks source link

Sleep Mode - Wake up Interrupt Enable #246

Closed madhavanatmel closed 2 years ago

madhavanatmel commented 2 years ago

hi , i am trying to use sleep mode and wake up by interrupt. i am little confused by interrupt pin exactly which interrupt pin i have use for wake up . also request you small example code sleep and wake up on atmega32.

`const int ledpin=0; const int sleepkey=20; const int wakeupkey=2;

volatile bool once = true; volatile int i =0;

void setup() {

pinMode(wakeupkey,INPUT_PULLUP);

Serial.begin(9600); pinMode(ledpin,OUTPUT); pinMode(sleepkey,INPUT_PULLUP);

attachInterrupt(digitalPinToInterrupt(wakeupkey), wake, FALLING);

}

void loop() {

digitalWrite(ledpin,HIGH);

if((digitalRead(sleepkey)==LOW) && once == true){

Serial.println(" Sleep "); 
delay(500);
once = false;
sleepMode(SLEEP_POWER_DOWN);
sleep();

}

}

void wake() {

Serial.println("Wakeup"); i++; Serial.println(i);
once = true; //noSleep(); }`

madhavanatmel commented 2 years ago

Wake up will happen by Pin no 3 - Interrupt 2 INT2