Skip to content

Snoozeblock overwritten when using multiple SnoozeBlocks in script #100

Open
@daanvV

Description

@daanvV

Hello!

I am trying to implement multiple snoozeblocks on a Teensy 3.2.

With the code below I would expect to see the following sequence of events happen:

  • Teensy goes to sleep for 5 seconds
  • LED blinks
  • Teensy goes to sleep for 10 seconds
  • LED blinks
  • 30 seconds delay
  • Teensy goes to sleep for 5 seconds
  • etc. etc.

What is actually happening is this:

  • Teensy goes to sleep for 10 seconds
  • LED blinks
  • Teensy goes to sleep for 10 seconds
  • LED blinks
  • 30 seconds delay
  • Teensy goes to sleep for 10 seconds
  • etc etc.

I get the impression that the command to hibernate with "config1" gets changed to "config2". In fact, even if I change both of the hibernate commands to "Snooze.hibernate(config1);", the Teensy still sleeps for 10 seconds on end, meaning that in the definition of the snoozeblocks, the second SnoozeBlock is probably overwriting the first SnoozeBlock. I'm guessing this is a bug, right? Does anyone know a solution? Many thanks! 🙄🚀

#include <Snooze.h>


#define LED_PIN LED_BUILTIN

// Load drivers
SnoozeTimer timer1;
SnoozeTimer timer2; 

SnoozeBlock config1(timer1); 
SnoozeBlock config2(timer2); 


void setup() {

  pinMode(LED_PIN, OUTPUT); 
  timer1.setTimer(5000);// milli seconds

  timer2.setTimer(10000);


}

void loop() {
  int who = Snooze.hibernate(config1);
  blinkLED();
  blinkLED();
  blinkLED();
  blinkLED(); 
  
  int who2 = Snooze.hibernate(config2);  
  blinkLED();
  blinkLED();
  blinkLED();
  blinkLED(); 

 delay(30000);    

 
}


void blinkLED(void) {
  digitalWrite(LED_PIN, HIGH);
  delay(80);
  digitalWrite(LED_PIN, LOW);
  delay(80);
  digitalWrite(LED_PIN, HIGH);
  delay(80);
  digitalWrite(LED_PIN, LOW);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions