#include <avr/sleep.h>
void setup(){
// disable ADC
ADCSRA = 0;
pinMode(2,INPUT);
attachInterrupt (0, gotoSleep, RISING);
Serial.begin(9600);
Serial.println("reset");
}
void loop(){
}
void gotoSleep(){
Serial.println("gotoSleep");
detachInterrupt (0);
attachInterrupt (0, wake, RISING);
set_sleep_mode (SLEEP_MODE_IDLE);
sleep_enable();
sleep_cpu ();
detachInterrupt (0);
attachInterrupt (0, gotoSleep, RISING);
}
void wake(){
Serial.println("wake");
sleep_disable();
}
This simply doesn't work for me and I don't know why. After "reset", serial wont print anything. I have a multimeter hooked up to it so I know it's not going to sleep. I can get it to sleep fine if I put the sleep stuff in the setup. But if I comment out all of the sleep and interrupt lines in the gotoSleep function, it calls gotoSleep just fine when I press the button.
I must be missing something very obvious.