Turning screen off then on again, but it's not reprinting everything

@red_car
I want to turn my screen off at night, but when the screen comes back on in the morning, it doesn't reprint everything. Why is that?

void loop() {
unsigned int IntensityOfLight;

  IntensityOfLight = analogRead(A0);

  myRTC.updateTime();
  sensors.requestTemperatures();

  if (IntensityOfLight >= 500) {
    tft.fillScreen(BLACK);
  }
  else {
    if (myRTC.dayofmonth != prevDay)
    {
      prevDay = myRTC.dayofmonth;

      tft.setCursor(5, 3);
      tft.fillRect(5, 3, 33, 21, BLACK);
      if (myRTC.dayofmonth < 10)
      {
        tft.print("0");
        tft.print(myRTC.dayofmonth);
      }
      else
      {
        tft.print(myRTC.dayofmonth);
      }
      moonPhase();
    }
    tft.setCursor(41, 3);
    tft.print("/");
    if (myRTC.month != prevMonth)
    {
      prevMonth = myRTC.month;
      tft.setCursor(59, 3);
      tft.fillRect(59, 3, 33, 21, BLACK);
      if (myRTC.month < 10) {
        tft.print("0");
        tft.print(myRTC.month);
      }
      else {
        tft.print(myRTC.month);
      }
    }
    tft.setCursor(95, 3);
    tft.print("/");
    if (myRTC.year != prevYear)
    {
      prevYear = myRTC.year;
      tft.setCursor(113, 3);
      tft.fillRect(113, 3, 70, 21, BLACK);
      tft.print(myRTC.year);
    }
    if (myRTC.hours != prevHour)
    {
      prevHour = myRTC.hours;
      tft.setCursor(246, 3);
      tft.fillRect(246, 3, 33, 21, BLACK);
      if (myRTC.hours < 10) {
        tft.print("0");
        tft.print(myRTC.hours);
      }
      else {
        tft.print(myRTC.hours);
      }
    }
    tft.setCursor(279, 3);
    tft.print(":");
    if (myRTC.minutes != prevMin)
    {
      prevMin = myRTC.minutes;
      tft.setCursor(295, 3);
      tft.fillRect(295, 3, 33, 21, BLACK);
      if (myRTC.minutes < 10) {
        tft.print("0");
        tft.print(myRTC.minutes);
      }
      else {
        tft.print(myRTC.minutes);
      }
    }
    tft.setCursor(329, 3);
    tft.print(":");
    if (myRTC.seconds != prevSec)
    {
      prevSec = myRTC.seconds;
      tft.setCursor(345, 3);
      tft.fillRect(345, 3, 33, 21, BLACK);
      if (myRTC.seconds < 10) {
        tft.print("0");
        tft.print(myRTC.seconds);
      }
      else {
        tft.print(myRTC.seconds);
      }
    }
    int sensor = analogRead(A1);
    float voltage = (sensor * 5.0) / 1023;
    tft.setTextSize(3);
    if (voltage != prevVolt)
    {
      prevVolt = voltage;
      battery();
    }
    if (sensors.getTempCByIndex(0) != prevTemp)
    {
      prevTemp = sensors.getTempCByIndex(0);
      tft.setCursor(5, 294);
      tft.fillRect(5, 294, 90, 21, BLACK);
      tft.print(sensors.getTempCByIndex(0));
    }
  }
}

Probably because your "prev" variables are still equal to the variables in your program, so they don't trigger updating the screen.

One way to force them to update, is when you turn the screen off (set it black) also set the "prev" variables to some value that they will never be, like 99. Then when it becomes light again all of the variables won't match their "prev" values and they will get reprinted.

@red_car

unsigned int IntensityOfLight;

  IntensityOfLight = analogRead(A0);

  myRTC.updateTime();
  sensors.requestTemperatures();

  if (IntensityOfLight >= 500) {
    tft.fillScreen(BLACK);
    prevDay = 99;
    prevMonth = 99;
    prevYear = 9999;
    prevHour = 99;
    prevMin = 99;
    prevSec = 99;
    prevTemp = 999.99;
    prevVolt = 9.99;
  }
  else {
    if (myRTC.dayofmonth != prevDay)
    {
      prevDay = myRTC.dayofmonth;

      tft.setCursor(5, 3);
      tft.fillRect(5, 3, 33, 21, BLACK);
      if (myRTC.dayofmonth < 10)
      {
        tft.print("0");
        tft.print(myRTC.dayofmonth);
      }
      else
      {
        tft.print(myRTC.dayofmonth);
      }
      tft.drawLine(0, 27, 480, 27, LIGHTGREY);
      tft.drawLine(0, 28, 480, 28, LIGHTGREY);
      tft.drawLine(240, 0, 240, 28, LIGHTGREY);
      tft.drawLine(241, 0, 241, 28, LIGHTGREY);

      tft.drawLine(0, 288, 480, 288, LIGHTGREY);
      tft.drawLine(0, 289, 480, 289, LIGHTGREY);
      tft.drawLine(240, 288, 240, 320, LIGHTGREY);
      tft.drawLine(241, 289, 241, 320, LIGHTGREY);

      moonPhase();
    }
    tft.setCursor(41, 3);
    tft.print("/");
    if (myRTC.month != prevMonth)
    {
      prevMonth = myRTC.month;
      tft.setCursor(59, 3);
      tft.fillRect(59, 3, 33, 21, BLACK);
      if (myRTC.month < 10) {
        tft.print("0");
        tft.print(myRTC.month);
      }
      else {
        tft.print(myRTC.month);
      }
    }
    tft.setCursor(95, 3);
    tft.print("/");
    if (myRTC.year != prevYear)
    {
      prevYear = myRTC.year;
      tft.setCursor(113, 3);
      tft.fillRect(113, 3, 70, 21, BLACK);
      tft.print(myRTC.year);
    }
    if (myRTC.hours != prevHour)
    {
      prevHour = myRTC.hours;
      tft.setCursor(246, 3);
      tft.fillRect(246, 3, 33, 21, BLACK);
      if (myRTC.hours < 10) {
        tft.print("0");
        tft.print(myRTC.hours);
      }
      else {
        tft.print(myRTC.hours);
      }
    }
    tft.setCursor(279, 3);
    tft.print(":");
    if (myRTC.minutes != prevMin)
    {
      prevMin = myRTC.minutes;
      tft.setCursor(295, 3);
      tft.fillRect(295, 3, 33, 21, BLACK);
      if (myRTC.minutes < 10) {
        tft.print("0");
        tft.print(myRTC.minutes);
      }
      else {
        tft.print(myRTC.minutes);
      }
    }
    tft.setCursor(329, 3);
    tft.print(":");
    if (myRTC.seconds != prevSec)
    {
      prevSec = myRTC.seconds;
      tft.setCursor(345, 3);
      tft.fillRect(345, 3, 33, 21, BLACK);
      if (myRTC.seconds < 10) {
        tft.print("0");
        tft.print(myRTC.seconds);
      }
      else {
        tft.print(myRTC.seconds);
      }
    }
    int sensor = analogRead(A1);
    float voltage = (sensor * 5.0) / 1023;
    tft.setTextSize(3);
    if (voltage != prevVolt)
    {
      prevVolt = voltage;
      battery();
    }
    if (sensors.getTempCByIndex(0) != prevTemp)
    {
      prevTemp = sensors.getTempCByIndex(0);
      tft.setCursor(5, 294);
      tft.fillRect(5, 294, 90, 21, BLACK);
      tft.print(sensors.getTempCByIndex(0));
    }
  }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.