Hi,
I am using an Arduino Pro Mini for a state of charge battery application but I don't want the device to fully discharge it when not being used for long.
For that, my intention would be to use the "LowPower" library so I can run my code and send it to sleep for 8 seconds in a periodic way. However, I would also like to be able to wake it up by myself using a push-button that also triggers some LED's.
As a basic idea I was thinking in a code like this,
#include "LowPower.h"
// Use pin 2 as wake up pin
const int Button = 12;
int wakeUpPin = digitalPinToInterrupt(Button);
// Used to determine if board woke up from an interrupt
bool interrupt = false;
void wakeUp()
{
// Just a handler for the pin interrupt
interrupt = true;
}
void setup()
{
Serial.begin(9600);
pinMode(Button, INPUT);
}
void loop()
{
attachInterrupt(wakeUpPin, wakeUp, LOW);
LowPower.idle(SLEEP_8S, ADC_OFF, TIMER2_OFF, TIMER1_ON, TIMER0_OFF, SPI_OFF, USART0_OFF, TWI_OFF);
detachInterrupt(wakeUpPin);
if (interrupt) {
// Woke up from an interrupt
interrupt = false;
digitalWrite(LED1, HIGH);
digitalWrite(LED2, HIGH);
digitalWrite(LED3, HIGH);
digitalWrite(LED4, HIGH);
digitalWrite(LED5, HIGH);
} else {
// Woke up by itself
}
}
Could somebody verify this? I would really appreciate some feedback from the experts
Thank you!!