Most of the examples I’ve seen around are opposite of what I’m doing.
I would like to use the external internal pin interrupt to put the Uno to sleep.
Let’s say I have a switch that’s Normally Close that’s connected to Pin2. This is the normal mode.
When the switch flicks to and changes state to Open, I want to use the interrupt to put the Uno to sleep. And when the switch goes back to Close, wake up and back to normal mode.
I scribbled the sketch below and I would like to know if it makes sense.
// interrupt service routine in sleep mode
void gotosleep ()
noInterrupts (); // make sure we don’t get interrupted before we sleep
sleep_enable (); // enables the sleep bit in the mcucr register
interrupts (); // interrupts allowed now, next instruction WILL be executed
sleep_cpu (); // here the device is put to sleep
} // end of sleep
void loop ()
attachInterrupt (0, gotosleep, LOW); // sleep on low level
sleep_disable (); // first thing after waking from sleep:
detachInterrupt (0); // stop LOW interrupt