Adaptive sleep time
-
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
-
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?
-
@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 } -
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 😅
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login