I think you may still be able to get it faster. I'd forgotten that the code I suggested triggered on both edges. You may be able to use 'lastTime' to measure the pulse width, while only triggering on the falling edge:
function sigOff(e) {
var d=e.time-e.lastTime;
if (d>0.0004 && d<0.0013) n+=(d>0.0008)?1:0;
else{
if (n.length==32) console.log(n);
n="";
}
}
wr=setWatch(sigOn,C6,{repeat:true,edge:"falling"});
You may also be able to use debounce to remove the check for small pulses, but I'd try that code first. it does rely on finding an abnormal pulse after the data is sent, but you can pretty much rely on that - otherwise I guess you could have an interval that checked the length of n every 100ms.
I'd be interested to know how it goes. If we get something working well, I'd really like to turn it into a module that others can use.
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.
I think you may still be able to get it faster. I'd forgotten that the code I suggested triggered on both edges. You may be able to use 'lastTime' to measure the pulse width, while only triggering on the falling edge:
You may also be able to use debounce to remove the check for small pulses, but I'd try that code first. it does rely on finding an abnormal pulse after the data is sent, but you can pretty much rely on that - otherwise I guess you could have an interval that checked the length of
n
every 100ms.I'd be interested to know how it goes. If we get something working well, I'd really like to turn it into a module that others can use.