-
• #2
Looking at the guide lines to measure things - decay of a charge - is not the most enticing for Javascript... It would have to go low level to catch the times... may be with some help from @ClearMemory041063 his ideas outlined in Peeking at Espruino Board Timers 2, 3, 4, and 5 conversation... ...with a
setWatch()
implemented on timersTx
(---> @Gordon), it would become quite manageable... But may be @Gordon has the silver bullet that can dodge the timing constraints... -
• #3
@allObjects yes, you could go all out trying to use the built-in hardware on 8 channels simultaneously to get really accurate results... Because you're just measuring pulse lengths you can use @ClearMemory041063's code (or this for the Pico) as is (without having to have anything running on interrupt), because you don't care if you miss a reading or not (the latest value will always be in the register).
OR you could just do what the Arduino code does, which only needs 4 lines of code and works on any pin:
function getLight(pin) { var c=0; pin.set(); while(pin.read())c++; return c; }
I reckon that would work relatively well - you might get one or two glitchy readings but on the whole it'd be good enough.
-
• #4
As far as using timers is concerned, there is a timer method that I've yet to implement, Input Capture. This would allow 4 signals per timer to be measured. In Input Capture mode the timer is clocked by the internal clock. When one of the 4 input channels sees a signal on it's pin the counter value is copied into a separate register that a peek command can access. Hopefully within a week or so I'll get to the input capture modes part of the project.
p382 RM0008 Reference manual 15.3.5 Input capture mode
http://www.st.com/content/ccc/resource/technical/document/reference_manual/59/b9/ba/7f/11/af/43/d5/CD00171190.pdf/files/CD00171190.pdf/jcr:content/translations/en.CD00171190.pdf
As far as I can find, there are no Espruino modules yet for IR reflectance sensor arrays like the QTR-8RC from Pololu (https://www.pololu.com/product/961). I would really like to use it for some simple line following stuff but writing a module is probably out of my league. I'm wondering if anyone else has already done it or has an interest in writing the module. Looks like a library already exist for Arduino so maybe an Espruino module wouldn't need to be totally from scratch.