Hi all,
Pretty new to the arduino space and C++ so please excuse if I am doing something wrong. I've connected the MKR to 2 buttons, one to turn on the device from sleep from pin 5, and I'd like to make the other on pin 4 to put it to sleep. I've individually tested the wake-up code, and can say that that works (with the interrupt). However, the code to put the MKR results in everything freezing in serial monitor and the device doesn't go sleep. I then have to double press reset to be able to do anything. Would anyone please shed some light on what might be causing this? Thank you so much ! <3
#include "ArduinoLowPower.h"
int sysState=1;
const int sleep_pin = 4;
const int wake_pin= 5;
void setup() {
Serial.begin(9600);
pinMode(sleep_pin, INPUT);
pinMode(wake_pin, INPUT);
attachInterrupt(digitalPinToInterrupt(sleep_pin), sleeping, RISING);
LowPower.attachInterruptWakeup(digitalPinToInterrupt(wake_pin), woken, RISING);
}
void loop() {
for (int i=0;i<10;i++){
Serial.println(i);
delay(1000);
}
}
void sleeping(){
sysState=0;
Serial.print("going to sleep");
LowPower.sleep();
}
void woken(){
if (sysState==0){
sysState=1;
delay(3000);
Serial.print(sysState);
delay(2000);
Serial.print("ive woken up");
}
else if (sysState==1){
;
}
}