Adaptive sleep time


  • Mod

    I am looking into a way to proportionally increase the sleep time as the voltage of the battery/supercap decreases. I have tried with map function but I think I messed up and getting weird results. I am looking for suggestions to make something flexible that can be set to a minimum sleep time and a max. At the moment a made something that works in fixed steps but it is not very elegant nor very flexible



  • @gohan At first approach, I would say the map function should be the way to go.. what is it that it's working weird?



  • Would it be possible to divide the sleeptime with the voltage? As the voltage is getting lower the sleeptime will be higher?

    Start with a number that after dividing sems good. Then it will automatically increase when voltage decrease.


  • Mod

    @manutremo I don't have the code with me, but if you are kind enough could you post a map function that you think could work.



  • @gohan If I understood correctly what you are trying to achieve, do you think this could work?

    #define VOLT_MAX 3.7
    #define VOLT_MIN 3.0
    #define SLEEP_MAX 100000
    #define SLEEP_MIN 10000
    
    void setup() {
      // put your setup code here, to run once:
    
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
    
    float v,p,s;
    
    v=3.5;          // Result from volt reading routine
    
    p=(v-VOLT_MIN)/(VOLT_MAX-VOLT_MIN);
    
    p=constrain(p, 0, 100);
    
    s=map(p, 0, 100, SLEEP_MAX, SLEEP_MIN);
    
    sleep (s, true);             // true for smartsleep, false if otherwise
    }
    

  • Mod

    Thanks a lot, I'll look at it in the next days. Today I woke up at 5 am and returned home at 8pm... My neurons are not very cooperative at the moment 😅


  • Mod

    @gohan so it's actually you who needs a set sleep time based on energy levels? 😉


Log in to reply
 

Suggested Topics

  • 1
  • 2
  • 5
  • 1
  • 6
  • 3

0
Online

11.4k
Users

11.1k
Topics

112.6k
Posts