TempSensor.prototype.getTempValue = function () {
var w = new Waveform(128/* your buffer size */,{doubleBuffer:false, bits:16});
var p = this.aPort;
w.on("finish", function(buf) {
var first = true;
var myarr = w.buffer;
myarr.sort();
// cut off first and last 2 elements
var view = new Uint16Array(myarr.buffer, 2/*sizeof(uint16)*/*2, myarr.length-4);
var vOut = E.getAnalogVRef() * E.sum(view)/(view.length*65536); // if you attached VOUT to Ao
var vZero = 0.4;
var tCoeff = 19.5 / 1000;
var tempinc = (vOut - vZero) / tCoeff;
var tempinf = tempinc * (9 / 5) + 32;
console.log("Temp in C: " + tempinc);
console.log("Temp in F: " + tempinf);
console.log("myarr: " + myarr.buffer);
console.log("view: " + view);
//console.log(E.sum(view)/(view.length*65536));
});
w.startInput(p,2000 /* Samples per second */);
};
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.
Working code: