Code that works:
function onInit() { var cmd=""; Serial1.setup(9600/*baud*/); Serial1.onData(function (e) { console.log("RX Data: " + e.data); }); function getResTempValue(x) { var temp=0; var avgTemp=0; var tfixed=0; for (var i=0;i<x;i++) { var vOut = E.getAnalogVRef() * analogRead(A0); // 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; temp = temp + tempinf; console.log(temp); console.log(i); } temp = temp / x; tfixed = temp.toFixed(2); console.log("Temp: " + tfixed); return temp; } getResTempValue(10); } onInit();
@d0773d started
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.
Code that works: