Hi - I think one issue is that digitalPulse is asyncronous - the pulse happens in the background.
You might have more luck changing it to:
At 1uS pulses, the above will be fine (due to code execution speed it's very unlikely to ever exceed 1uS there :)
Also, as far as I can tell, the gain is selected by the number of clock pulses. I think (and this could be the main issue) the loop you have (for (var o=0; o<gain;o++)) should be after the main loop, not inside it. It's not quite indented right (where you read the bit) and that might have made you think the for loop had ended when it actually hadn't
for (var o=0; o<gain;o++)
As it is, I think instead of sending 25 pulses (24+1) you're actually sending 48 (24*2).
Hope that helps!
© Espruino, powered by microcosm.
Report a problem