• 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();
    
About

Avatar for d0773d @d0773d started