Hello,
I'm using an arduino mega 1280 and am running into a small issue. I enter sleep mode but cannot disable it once I enter sleep mode.
My code is the following:
#include <avr/sleep.h>
int counter =0;
void setup()
{
Serial.begin(9600);
attachInterrupt(0,wake, RISING);
}
void loop()
{
counter++;
delay(1000);
if (counter == 5)
{
sleepNow();
}
}
void wake()
{
Serial.println("WORKING");
}
void sleepNow()
{
Serial.println("SET_SLEEP_MODE");
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // sleep mode is set here
Serial.println("SLEEP_ENABLE");
sleep_enable(); // enables the sleep bit in the mcucr register
// so sleep is possible. just a safety pin
attachInterrupt(0,wake, RISING);
Serial.println("SLEEP_MODE");
sleep_mode(); // here the device is actually put to sleep!!
// THE PROGRAM CONTINUES FROM HERE AFTER WAKING UP
Serial.println("SLEEP_DISABLE");
sleep_disable(); // first thing after waking from sleep:
// disable sleep...
Serial.println("MCU is back in business");
}
My output is the following:
WORKING //Press the button to make sure interrupt is working BEFORE entering sleep mode
SET_SLEEP_MODE
SLEEP_ENABLE
SLEEP_MODE
//I press the button as many times as I want but never seem to get any response from the arduino.
Can someone please tell me what I'm doing wrong ?