@bigplik you can't use a for loop for that kind of thing - because getADC is asynchronous.
You need to use callbacks, so that you issue the next reading only after you got the last one. For instance:
var idx = 0;
var array = new Float32Array(10);
function getValue(value) {
array[idx] = value;
idx++;
if (idx<array.length)
ads.getADC(0, getValue);
}
ads.getADC(0, getValue);
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.
@bigplik you can't use a
for
loop for that kind of thing - becausegetADC
is asynchronous.You need to use callbacks, so that you issue the next reading only after you got the last one. For instance: