-
• #2
Thanks!
Are you using an up to date firmware though? I just tried here and I don't seem to be able to reproduce it...
>LED1.write(1); =undefined >LED1.write(0); =undefined >Puck.light() =0.66570218404 >Puck.light() =0.64452409744
It's possible that the older firmware is using different code that doesn't have any delay in it at all?
-
• #4
I'm also doing analogWrite(LED1, xxx) elsewhere in my code, if that makes a difference.
Ahh, you didn't mention that bit ;) Just normal analogWrite, or the forced software version?
Did you experiment with different timeouts? I'm not sure how I feel about this - making
Puck.light
10 times slower just to deal with the very first reading in the case where someone is usinganalogWrite
andPuck.light
may not actually be in most people's best interests :) -
• #5
I called it exactly as above, not with the
forceSoft
option.I tried different timeouts; 50ms seemed the minimum in my code to get consistency. I'm fine with a 1/20 second reading in my use case. You also mention not taking more than 5 readings/second, so that's a gating factor, anyway.
You could also have a
highAccuracy
option (or simple Boolean) inPuck.light()
, that when present, adds a bit more delay.I'm using this, BTW, in a kitchen-sink app that exercises all the sensors, incl NFC, and the RGB LEDs. I'll share that here soon.
-
• #6
I guess maybe the thing to do would be to detect of the pin state was af_output, and if so to wait the full 50ms - otherwise just the 5ms should do it.
-
• #7
That sounds like an elegant solution – especially as it requires no user attention.
-
• #8
I did that today, so it'll be in the 1v92 release :)
@Gordon,
Puck.light()
is returning lower values than expected after the first call. Probably because I'm lighting up LED1.Short story: I think this can be fixed by extending the settling time delay in
jswrap_puck_light()
.I type this in the console, and I get:
The last 0.559 reading is the most accurate.
Here's my workaround that gives consistent light readings:
Like your C code for
jswrap_puck_light()
, I reset the LED1 pin, take a reading, wait, and take another (better) reading. But I wait 50 milliseconds, rather than 5 milliseconds.