Just place all your processing into the anoymous funtion - either inline defined - or outside defined.
For inline/anonymous, it would look - for channel 0 - like this:
ads.getADC(0, function(val0) {
// do calculations specific for channel 0 with read value val0
// print the result
});
A 'better' way would be to define upfront functions for the different - channel specific - haendling which include: receiving, processing, and printing. This allows to re-use the handlers for more than just one channel, if needed.
var handle_the_A_way(val) {
// do calculations specific for A with read value val
// print the result
};
var handle_the_B_way(val) {
// do calculations specific for B with read value val
// print the result
};
The 'main' flow of your application will include something like that - logically:
I said logically, because a next adsGetADC() invocation can only be issued when the previous one has finished... In other words, the requests have to be enqueued, so that only one after the other is executed. Complexity depends on the reading schedule for each channel. What is for sure, you cannot read faster than a channel can deliver.
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.
Just place all your processing into the anoymous funtion - either inline defined - or outside defined.
For inline/anonymous, it would look - for channel 0 - like this:
A 'better' way would be to define upfront functions for the different - channel specific - haendling which include: receiving, processing, and printing. This allows to re-use the handlers for more than just one channel, if needed.
The 'main' flow of your application will include something like that - logically:
I said logically, because a next
adsGetADC()
invocation can only be issued when the previous one has finished... In other words, the requests have to be enqueued, so that only one after the other is executed. Complexity depends on the reading schedule for each channel. What is for sure, you cannot read faster than a channel can deliver.Other postings cover the sequencing of (dependent) callbacks (see squence controller - lines 20..30.