After my initial post I tried something similar to what @allObjects is suggesting:
pinMode(D1,"input_pullup");
var rawtimes = [];
var calculatedTimes = [];
function onPulseOn(e) {
rawtimes.push(getTime());
}
function onPulseOff(e) {
rawtimes.push(getTime());
}
setWatch(onPulseOff, D1, { repeat:true, edge:"rising" });
setWatch(onPulseOn, D1, { repeat:true, edge:"falling" });
setWatch(function(e) {
// if we have timings
if (rawtimes.length > 0)
{
calculatedTimes = [];
var lasttime = 0;
rawtimes.forEach(function(rawTime) {
if(lasttime != 0)
{
var newTime = 1000 * (rawTime - lasttime);
calculatedTimes.push(parseFloat(newTime.toFixed(3)));
}
lasttime = rawTime;
});
}
//send to IR
Puck.IR(calculatedTimes);
console.log(calculatedTimes);
calculatedTimes = [];
}, BTN, { repeat: true, edge: 'rising', debounce: 50 });
This gets me close to what I'm expecting but still does not perform the function when replayed via the puck ir. I believe the tolerance for IR signals is +-10% which some of my recorded times fall out of.
Here's the a snippet my new recorded times:
[ 8.972, 4.547, 0.61, 0.763, 0.61, 0.763, 0.579, 1.19, 0.61, ...
Correct working times are:
[ 9.024 ,4.512 ,0.564 ,0.564 ,0.564 ,0.564 ,0.564 ,1.692, 0.564, ...
So the pattern seems to be there. I wonder if it's due to the reading at 32kHz?
I'll try @allObjects code out tonight see if I get any closer.
Also @Gordon is it correct that with the code below e.time and e.lastTime are rounded to 3 decimal places or is this a bug/limitation?
setWatch(function(e) {
var pulseLen = (e.time - e.lastTime);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
Thanks for the replies.
After my initial post I tried something similar to what @allObjects is suggesting:
This gets me close to what I'm expecting but still does not perform the function when replayed via the puck ir. I believe the tolerance for IR signals is +-10% which some of my recorded times fall out of.
Here's the a snippet my new recorded times:
[ 8.972, 4.547, 0.61, 0.763, 0.61, 0.763, 0.579, 1.19, 0.61, ...
Correct working times are:
[ 9.024 ,4.512 ,0.564 ,0.564 ,0.564 ,0.564 ,0.564 ,1.692, 0.564, ...
So the pattern seems to be there. I wonder if it's due to the reading at 32kHz?
I'll try @allObjects code out tonight see if I get any closer.
Also @Gordon is it correct that with the code below e.time and e.lastTime are rounded to 3 decimal places or is this a bug/limitation?
I look forward to your video on this :)