I´m using LowPower.h
and PinChangeInt.h
libraries to put my Arduino into the sleep mode every 8 seconds and then it wakes up, modifies a counter and it goes to sleep again, but also I need to wake it up when a button is pressed asynchronously.
I´ve reached to wake up the Arduino every 8 seconds using LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF)
and, in other code, I´ve also reached to wake it up while it sleeps indefinitely with LowPower.powerDown(SLEEP_FOREVER, ADC_OFF, BOD_OFF)
but I can´t combine that periodical awakening with the asynchronous awakening.
Here is my code:
void setup(){
Serial.begin(9600);
//Pines declaration
loopsToSend = setTimeToSend(); //
//The three async buttons
PCintPort::attachInterrupt(4, readOpinion,RISING);
PCintPort::attachInterrupt(5, readOpinion,RISING);
PCintPort::attachInterrupt(6, readOpinion,RISING);
}
void loop(){
if(loops < loopsToSend ){
byte opinionValue = readOpinion(); //This method must awake the Arduino ASYNC to give a value to the opinionValue var, write the result in the file and go to sleep
if(opinionValue != 0){
Serial.println("Button pressed!");
//Writing result in a file
opiniones++;
delay(500);
}
//Go to sleep 8 seconds
LowPower.powerDown(SLEEP_8S, ADC_OFF, BOD_OFF);
opinionValue = 0;
}
else {
wdt_disable();
if(opiniones > 0){
//Send file using GSM module
}
else{
loops = 0;
}
}
loops++;
}
Can anyone help me? Thanks
PinChangeInt.h
to use any pin to generate the interrupt and it works.