...and for the processing you have to apply the 'delay pattern' to 'wait until all readings happened'. Therefore, add something like this after line 7 in code above (note the curly bracket added to the end of line 6):
var idx = 0;
var array = new Float32Array(10);
function getValue(value) {
array[idx] = value;
idx++;
if (idx<array.length) {
ads.getADC(0, getValue);
} else {
// processing of the 10 values, for example, calculating the mean:
console.log( "Mean of 10 channel 0 values: "
+ array.reduce(function(s,v){ return s + v; }, 0) / array.length );
}
}
}
ads.getADC(0, getValue);
Mean may not be the right thing to do because there may be values outside expected confidence interval.
This solves only the ten first readings for channel 0... What about the other channels... and then the subsequent readings at intervals of...
With all this nesting of callbacks, you end up in callback hell. Most sophisticated solution are Promises... and these aren't the easiest thing to grasp either.
For a first 'cut' to get all four channels read 10 times and after that every 30 seconds, see next post.
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.
...and for the processing you have to apply the 'delay pattern' to 'wait until all readings happened'. Therefore, add something like this after line 7 in code above (note the curly bracket added to the end of line 6):
Mean may not be the right thing to do because there may be values outside expected confidence interval.
This solves only the ten first readings for channel 0... What about the other channels... and then the subsequent readings at intervals of...
With all this nesting of callbacks, you end up in callback hell. Most sophisticated solution are Promises... and these aren't the easiest thing to grasp either.
For a first 'cut' to get all four channels read 10 times and after that every 30 seconds, see next post.