MKR and DeepSleep Clock problem

Hello,
I work with MKR board and would like to bring them in deep sleep until an external interrupted triggered. If multiple interrupts came within 2 seconds I would like ignore them.

The following code only works without deepSleep.
Is there anything I have to handle additional?

#include <ArduinoLowPower.h>
#define PIN_SENSOR_IN 0

volatile boolean trigger = false;
void setup() {
  pinMode(PIN_SENSOR_IN, INPUT_PULLUP);
  LowPower.attachInterruptWakeup(PIN_SENSOR_IN, pulseSensorTriggered, FALLING);
}

void loop() {
  if(trigger){
   //do something
  trigger = false;
  }
  LowPower.deepSleep(); //without is works 
}

void pulseSensorTriggered(){
  static unsigned long last_interrupt_time = 0;  // put this already as global because of longer time 
  unsigned long interrupt_time = millis();  
    if ( interrupt_time - last_interrupt_time > 2000 ) { //should trigger not within 2 seconds
       trigger = true;
       last_interrupt_time = interrupt_time;
    }
}

hope you understand my problem and have some inputs for me

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.