• That's great! Some quick ideas:

    • Try using a 'normal' array and use data.push(...) to append, rather than referencing individual elements (this may be faster but I'm not 100% sure)
    • Define data locally as a single character variable name (d)
    • Count down towards zero (which will marginally speed up the loop)
    • Don't do the subtraction of time in the main loop

    Something like this might be faster:

    function read() {
      var t=getTime();
      var d = [];
      for (var i=samples; i>0;i--) d.push([getTime(),analogRead(C1),analogRead(C5)]);
      for (i in d) d[i][0]-=t;
      return d;
    }
    ...
    var data = capture();
    

    It's all a bit nasty though. I'm actually working on a Waveform class which will allow you to capture and play back analog values. Initial tests look like it'll be able to do it at ~100kHz.

About

Avatar for Gordon @Gordon started