• 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:

    ads.getADC(0, handle_the_A_way);
    ads.getADC(1, handle_the_A_way};
    ads.getADC(2, handle_the_B_way};
    ads.getADC(3, handle_the_A_way};
    ...
    ...
    ...
    

    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.

About

Avatar for allObjects @allObjects started