hi there,
im trying to have my bare bones arduino go into sleep and then woken up with an interrupt, sounds typical i know!
the following is sample code that is not working for me
#include <avr/sleep.h>
int wakePin = 2;
int changeThisPin = 1;
void setup() {
pinMode(wakePin, INPUT);
pinMode(changeThisPin, OUTPUT);
digitalWrite(changeThisPin, HIGH);
}
void loop() {
delay(3000);
sleep();
}
void sleep()
{
sleep_enable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
attachInterrupt(0, wakeUpNow, LOW);
digitalWrite(changeThisPin,LOW);
delay(2000);
sleep_mode();
sleep_disable();
detachInterrupt(0);
digitalWrite(changeThisPin,HIGH);
}
void wakeUpNow()
{
// wake up code here if needed
}
basically, pin 1 it set to high. then in loop i wait 3 seconds, then call sleep. there i am turning the pin to low, settings the sleep mode, attaching an interrupt to ping 2 (0 = pin 2 in interrupt params)), then i am waiting 2 seconds before actually putting the cpu to sleep.
at this point, what i am expecting is to not see pin1 go back to a high state until pin 2, the interrupt, is placed to ground. but this is not the case, what actually is happening is the code just simply continues right past the sleep mode and goes right back into loop.
i have a 4.7k resistor between pin 2 and the power rail on the bread board, which is being supplied 5v, so the pin is in a high state, the interrupt requires a low state to continue. my intention is to then have a button between pin 2 and ground to bring it to the low state, and waking the cpu back up.
i am using the following link for reference:
http://playground.arduino.cc/Learning/ArduinoSleepCode
any ideas on why the chip is not staying in sleep mode?
thanks