• I have some simple temperature display code which is giving me grief when I save() it to the Espruino. The code continues to run after a reset or power cycle but the characters are barely visible on the screen. It's like the contrast is turned down to almost zero. It works and displays fine when the same code is just uploaded and run directly. I've read all the threads about using onInit() but it's not helping at all.

    Any ideas? Code looks identical in both cases using dump() apart from the contents of g.buffer;

    Thanks

    var g;
    var rtc;
    var numReadings = 10;
    var temperatures = [];
    var index;                  // the index of the current reading
    var total;                  // the running total
    var average;                // the average
    
    function onInit() {
      index = 0;                  // the index of the current reading
      total = 0;                  // the running total
      average = 0; 
      SPI1.setup({ baud: 1000000, sck:B3, mosi:B5 });
      clearInterval();
    
      // initialize all the readings to 0:
      for (i = 0; i < numReadings; i++){
        temperatures[i] = 0;
      }
    
      digitalWrite(B13,0);
      I2C2.setup({scl:B10,sda:B11});
      rtc = require("DS3231").connect(I2C2);
    //  setInterval(function() {
    //    console.log(rtc.readDateTime());
    //  }, 1000);
    
      g = require("PCD8544").connect(SPI1,B6,B7,B8­, function() {
        g.clear();
        g.setContrast(0.45);
        g.flip(); // copy this to the screen
        setInterval(onTimer, 1000);
      });
    }
    
    function onTimer() {
    
      // subtract the last reading:
      total = total - temperatures[index];
    
      var val = analogRead(C0);
      temperatures[index] = (((val*3.3)-1.25)/0.005);
    
      //console.log("Total: " + total);
      //console.log("Temperature: " + temperatures[index]);
    
      // add the reading to the total:
      total = total + temperatures[index];
    
      // advance to the next position in the array:
      index = index + 1;
    
      // if we're at the end of the array...
      if (index >= numReadings){
        // ...wrap around to the beginning:
        index = 0;
      }
    
      // calculate the average:
      average = total / numReadings;
    
      //console.log("Average: " + average);
    
      g.clear();
      g.setContrast(0.45);
      g.setFontBitmap(); // simple 8x8 font
      g.setFontVector(20); // large font
      g.drawString(average.toFixed(2), 0, 0);
      g.drawString("C", 65, 0);
      g.setFontVector(15); // large font
      var localtime = rtc.readDateTime().split(" ")[1];
      g.drawString(localtime, 0, 32);
      g.flip(); // copy this to the screen
    }
    
    onInit();
    
    
About

Avatar for conor @conor started