Hello Everyone, I m a newbie, and i m working on a small project using arduino Uno. I want my arduino to be on Idle mode to save power since i will be recharging my battery from time to time. I would also want to write a program that will put my arduino to sleep and then activate it with FSR sensor. Based on all my readings and research from this site, i came across with the code at below, but i did not fully understand the code and i hopping that someone will take a look at the code and tell me if the code is what i needed or if i need more code to add into it for it serve my purpose. I would also like to use LED to show the interrupt . For example; i would like my code to show LED red light on when it is on IDLE mode and when FSR sensor is pressed, the green LED will be on showing that arduino is fully active. I also understand that the code uses Interrupt on Pin 2 to wake up.
#include <avr/sleep.h> // powerdown library
#include <avr/interrupt.h> // interrupts library
//***************************************************
// * Name: pin2Interrupt, "ISR" to run when interrupted in Sleep Mode
void pin2Interrupt()
{
/* This brings us back from sleep. /
}
//**************************************************
//***************************************************
// * Name: enterSleep
void enterSleep()
{
/* Setup pin2 as an interrupt and attach handler. /
attachInterrupt(0, pin2Interrupt, LOW); // << LOW, HIGH, FALLING, RISING I think are valid
delay(50); // need this?
/ the sleep modes
SLEEP_MODE_IDLE - the least power savings
SLEEP_MODE_ADC
SLEEP_MODE_PWR_SAVE
SLEEP_MODE_STANDBY
SLEEP_MODE_PWR_DOWN - the most power savings
*/
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // setting up for sleep ...
sleep_enable(); // setting up for sleep ...
sleep_mode(); // now goes to Sleep and waits for the interrupt
/* The program will continue from here after the interrupt. */
detachInterrupt(0); //disable interrupts while we get ready to read the keypad
/* First thing to do is disable sleep. */
sleep_disable();
// then go to the void Loop()
}
//***************************************************
//***************************************************
// within void loop() call this ...
enterSleep(); // call Sleep function to put us out
// THE PROGRAM CONTINUEs FROM HERE after waking up in enterSleep()