Using Snooze with Counter

Status
Not open for further replies.

grams

New member
I'm trying to use snooze to put a teensy 3.2 to sleep for 30 seconds. It will wake up and take some measurements and then go back to sleep. However I have a digital input that I need to track each time it changes in between the sleep events. The digital will toggle at a maximum interval of 500 milliseconds. Am I implementing the snooze library (v6.3.2) correctly for this scenario?
Code:
#include <Snooze.h>

// Load drivers
SnoozeDigital digital;
SnoozeTimer timer;
SnoozeUSBSerial usb;

SnoozeBlock sleep_config(usb, digital, timer);

int counter = 0;
unsigned long lastTrigger = 0;
const unsigned long debounceDelay = 500;

void setup() {
  while (!Serial);
  Serial.println("Staring...");

  pinMode(LED_BUILTIN, OUTPUT);

  digital.pinMode(0, INPUT_PULLUP, CHANGE); //pin, mode, type
  //pinMode(0, INPUT_PULLUP);       //Setup 0 Pin as input for counter
  //attachInterrupt(0, counterISR, CHANGE);

  timer.setTimer(5000);// milliseconds
}

void loop() {
  int who;
  /********************************************************
    feed the sleep function its wakeup parameters. Then go
    to deepSleep.
   ********************************************************/

  who = Snooze.deepSleep(sleep_config);// return module that woke processor

  if (who == 36) { // lptmr wakeup value
    for (int i = 0; i < 2; i++) {
      digitalWrite(LED_BUILTIN, HIGH);
      delay(200);
      digitalWrite(LED_BUILTIN, LOW);
      delay(200);
    }
  }
  else if (who == 0) {
    if ((millis() - lastTrigger) > debounceDelay) {
      lastTrigger = millis();
      ++counter;
    }
  }

  while (!Serial) {
    delay(30);
  }
  Serial.print("Counts: ");
  Serial.println(counter);
  delay(1000);

}


// ***********************************************************************************************************
// *                        ******* Interrupt Service Routines (ISR) *******
// ***********************************************************************************************************
// Interrupt handler
//void counterISR ()
//{
//  if ((millis() - lastTrigger) > debounceDelay) {
//    lastTrigger = millis();
//    ++counter;
//  }
//}  // ******** end of isr *******
 
Status
Not open for further replies.
Back
Top