SSD 1306 Buffer not clearing

I have a problem with clearing the SSD1306 buffer. No matter what I do I can't get it to clear after each "case." If I you observe in "Case 1" the line display.print( "TANK") it will display TANK in the display, but that display line will remain on the display when the sketch moves to "Case 2". You can see in the code below the display should change to "TANKTWO". but it just remains on "TANK".
The data (ie distance and voltage) do change. Any idea how to fix this?

  case 1:
      LoRa.readBytes((byte *)&struct1 + 1, packetSize - 1);  // receive struct1 packet
      struct1.StructureID = structureID;
      Serial.println(" Tank 1 ");
      Serial.print(struct1.seq);
      Serial.print(" distance 1 = ");
      Serial.print(struct1.distance);
      Serial.print(" voltage 1 = ");
      Serial.println(struct1.voltage);
      Serial.println();
      checkSeqNumber(struct1.NodeID, struct1.seq);

      display.clearDisplay();

      display.setTextSize(2);
      display.setCursor(30, 0);
      display.print("TANK");
       display.setTextSize(1);
      display.setCursor(0, 25);  //First line
      display.print("water down ");
      display.print(struct1.distance);
      display.print(" in");
      display.setCursor(0, 35);  //second line
      display.print("volts  ");
      display.print(struct1.voltage);
      display.display();
      delay(2000);
      break;

      // case 2:
 
      LoRa.readBytes((byte *)&struct2 + 1, packetSize - 1);  // receive struct1 packet
      struct1.StructureID = structureID;
      Serial.println(" Tank 2 ");
      Serial.print(struct2.seq);
      Serial.print(" water down = ");
      Serial.print(struct2.distance);
      Serial.print(" voltage is  ");
      Serial.println(struct2.voltage);
      Serial.println();
      checkSeqNumber(struct2.NodeID, struct2.seq);

       display.clearDisplay();

      display.setTextSize(2);
      display.setCursor(30, 0);
      display.print("TANKTWO");
       display.setTextSize(1);
      display.setCursor(0, 25);  //First line
      display.print("water down ");
      display.print(struct2.distance);
      display.print(" in");
      display.setCursor(0, 35);  //second line
      display.print("volts  ");
      display.print(struct2.voltage);
      display.display();
      delay(2000);
      break;

It doesn't work like that - that's a comment

Always post ALL the code.

when the sketch moves to "Case 2"

It will never reach the code following the "case 2:" comment.

Thanks, upon consideration I am coming to the conclusion that it’s not a display problem, but how the structure is setup.

The code is not correctly structured, if that is what you mean.

To clear "text" in COLOR of WHITE from the OLED, you must write that same "text" with COLOR of BLACK.

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