any gotchas using attachInterrupt(digitalPinToInterrupt()) and Snooze deepSleep?

Status
Not open for further replies.

DaQue

Well-known member
I need to detect a change from 1 to 0 that could happen in a Snooze deepSleep or it could happen outside of it in loop(). I'm not sure if an interrupt would play nice with Snooze and the interrupt itself may take a few days to happen so its kind of hard to test. This is my first time trying an interrupt on Teensy or Arduino so any pointers would be greatly appreciated.

before set up:
volatile bool testDone = FALSE; // only has to go low once (testDone==TRUE), it is never reset
void BatEOC(void) {
testDone = TRUE;
}

in setup():


pinMode(0, INPUT); // test point provides pull up source
attachInterrupt(digitalPinToInterrupt(0), BatEOC(), FALLING);


I will check for (testDone == TRUE) as part of my code in loop(), timing is not critical. loop() takes about 5 seconds with all the deepSleep's. As long as it catches it I'm good.

Am I missing anything thing that could cause issues?
 
Last edited:
Ok it looks like there are not any gotcha's. This seems to work like I wan't and catches going low from with in deepSleep inside a REDUCED_CPU_BLOCK.


Code:
#include <Snooze.h>
SnoozeTimer timer;
SnoozeBlock config_teensy32(timer);
SnoozeBlock dummyConfig;
volatile bool myLevel = HIGH;
void BatEOC() {
  myLevel = LOW;
}
elapsedMillis TestTime;
void flash( int x, int s = 500);

void setup() {
  timer.setTimer(10000);
  pinMode(0, INPUT); // test setup provides pull up
  pinMode(13, OUTPUT);
  attachInterrupt(digitalPinToInterrupt(0), BatEOC, FALLING);//<<<<<<<<<<



}
void loop() {
  REDUCED_CPU_BLOCK(dummyConfig) {
    while (1) {
      flash(3);
      Snooze.deepSleep( config_teensy32 );
      if (myLevel == LOW) flash(10, 100);
      myLevel = HIGH; digitalWrite(13, HIGH);
      delay(2000);

    }

  }
}

void flash( int x, int s) {
  digitalWrite(13, LOW);
  delay(s);
  for (int y = 0; y < x; y = y + 1) {

    digitalWrite(13, HIGH);
    delay(s);
    digitalWrite(13, LOW);
    delay(s);
  }
  digitalWrite(13, HIGH);
  delay(2000);

}
 
Status
Not open for further replies.
Back
Top