• Datasheet says "fast read time < 1mSec", so I am guessing you could theoretically get over 1000 samples per second. Not sure how fast that sort would be though, plus you are doing way more work than needed inside the loop.

    function AverageRead(n) {
      var sum = 0;
      for(i=0;i<n; i++){sum += analogRead(A0); }
      var avg = sum/n;
      var vZero = 0.4;
      var tCoeff = 19.5 / 1000;
      var tempinc = (E.getAnalogVRef()*avg - vZero)/tCoeff;
        var tempinf = tempinc * (9 / 5) + 32;
      return { 'C':tempinc, 'F':tempinf};
      }
    

    I know this doesn't throw away the 2 highest/lowest outliers like you were doing, but if you printed them, I bet they wouldn't be far from the average, especially if you are taking so many samples anyhow. But it does allow you to get rid of the big array and the sorting and you could easily do as many samples as you wanted now without eating up so much memory and you could do it just as fast now. But try it both ways and see how far apart the readings are :)

About

Avatar for Manxome @Manxome started