7 years, 9 months ago.

Is it possible to use 2 wake up object in same time?

I would like to use the WakeUp class to wakeup my STM32L073 from deepsleep. I would like to wakeup once a day and call a function and every 30s to call an other function.

Today, if I initialize 2 objects like "WakeUp Scheduler1, Scheduler2;" only one will works.

Is there a solution to use 2 objects simultanously?

Thanks.

2 Answers

7 years, 9 months ago.

Use the 30s wake up and increment a counter, when that gets to 2880 (should be 24 hours, but check, my maths is not that great) trigger your second scheduler and reset the counter.

7 years, 9 months ago.

If you make a question on the page of the library I get a mail it was asked :). (At least I assume this is regarding my lib)

You can't actually make two objects since it is a static class. While it would in principle be possible to make it non-static, where you can make several objects, as you shown in your question, but I decided to go for the static implementation, where as you can see in the example code, you don't actually make an object:

// Depending on the LED connections either the LED is off the 2 seconds
// the target spends in deepsleep(), and on for the other second. Or it is inverted 
 
#include "mbed.h"
#include "WakeUp.h"
 
DigitalOut myled(LED1);
 
int main() {
    //The low-power oscillator can be quite inaccurate on some targets
    //this function calibrates it against the main clock
    WakeUp::calibrate();
   
    while(1) {
        //Set LED to zero
        myled = 0;
        
        //Set wakeup time for 2 seconds
        WakeUp::set_ms(2000);
        
        //Enter deepsleep, the program won't go beyond this point until it is woken up
        deepsleep();
  
        //Set LED for 1 second to one
        myled = 1;
        wait(1);
    }
}
 

So yeah, Paul's solution is the one I would use, just wake it up every 30 seconds and keep track if the day already is passed.

Ok thanks you very much, I think i'll use Paul's solution :)

posted by Quentin Broizat 20 Jun 2016