Puck.js with LDR - how to deal with light that is always on? #3803
Replies: 12 comments
-
Posted at 2021-08-03 by @gfwilliams Actually yes, I guess you could remove the pullup if it's on for too long. So maybe some additional code:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-03 by user130485 Thank you!
Also, what is the difference between
in the beginning and
in the end? Or the first one suppose to be true and the last one false? |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-04 by @gfwilliams Did you try it at all? does it work? The idea is:
As it happens, because of the order of the |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-04 by user130485 well, it works but trying to understand how it saves power.
so I am trying to understand when does it actually set pinmode, if the condition when everything is ok is setting it to false... |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-04 by @gfwilliams
Lets say the LED is off, and pulledUp==false... The flow of execution looks like this:
So at the end of that, pulledUp==true, but |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-04 by user130485 but what if LED is on (stuck)? So the loop that reads it every 10s sets pin pull up and then sets to input. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-04 by @gfwilliams pinMode info is here: http://www.espruino.com/Reference#l__global_pinMode
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-04 by user130485 ok... I think I get it now =) thank you for your patience - my brain must be functioning in another way =) But running through it I feel I still dont get it =) Now, there is a brief pulse of LED light, which is a normal meter functioning, but outside the function's 10second loop.
I keep wanting to change
to
Just dont understand how it works without changing the pinMode if pulledUp variable is staying true on the "unstuck" day |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-05 by @gfwilliams
In this case, you'd hope that the In the case where the LED was on previously and then it turns off which I think is what you mean:
|
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-05 by user130485 problem is that it's called in interval and there is a high chance that during the day LED may flash in between the checks. |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-05 by @gfwilliams
Yes, that's fine. I should still work - and as far as I understand you tested and it does work?
As I said above, the pullup is enabled because it's like a 'potential divider'. When the light level is low, LDR resistance is high and the voltage on the pin goes high. When you have light, LDR resistance is low and it pulls the pin voltage low. But I'm sorry, I'm really busy this week and I can't spend any more time walking you through the code. I think I've already covered what it does line by line in every circumstance |
Beta Was this translation helpful? Give feedback.
-
Posted at 2021-08-05 by user130485 thank you for your help |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2021-08-03 by user130485
Hello
I thought I had my power meter puck all ready, but after about a week of successful running, I got into a problem that my power meter LED that blinks for every watt, gets stuck with LED always on =(
I have solar power and possibly it causes issues with a meter (have to call my power company).
Anyway... Is it possible to somehow work around the issue with the code?
This is my code to trigger on the light pulse, similar to the example code:
Not sure what I can do to detect that D2 is short for too long and somehow stop draining the battery if it gets stuck for too long. Once the sun sets, it goes back to normal blinking on power use
Beta Was this translation helpful? Give feedback.
All reactions