Hi
I’m using the following code:
displays = displays + 1;
if (displays > 3) {
displays = 0;
}
if ((displays == 0) or (displays == 1)) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print(tempc,1);
display.print(" Grad");
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.print(WindSpeedkt,1);
display.print(" kt");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,40);
display.print(CalDirection);
display.print(" deg");
// update display with all of the above graphics
display.display();
}
if ((displays == 2) or (displays == 3)) {
display.clearDisplay();
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,0);
display.print(tempc,1);
display.print(" Grad");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,20);
display.print(pressurehpa,2);
display.print(" hP");
display.setTextSize(2);
display.setTextColor(WHITE);
display.setCursor(0,40);
display.print(humidity,1);
display.print(" %");
// update display with all of the above graphics
display.display();
delay(3000);
}
The second page (displays 2 & 3) is working fine but on the “first” page only shows “kt” and “deg”, but “Grad” is messing there. Any advice?
That’s a typical copy-pasting error.
Your three times two printing blocks are obvously just copy-pasted and then “tweaked”. Easy to tell by the fact that you repeatedly set text size and color where is no need.
If you looked at the code you might have noticed that you obviously forgot to delete the display.clearDisplay();
line in the second copy/paste-block 
If you want to code rather than copy/paste, you’d “extract” all the common stuff (including the temp display) and only do that once and only do the other stuff on demand.
e.g.
void updateDisplay() {
static uint32_t ms = 0; // for non-blocking "delay"
int x = 0;
int y = 0;
char txt[16];
if (millis() - ms < 3000) return; // non-blocking "delay"
ms = millis();
// common to all display pages
display.clearDisplay();
display.setTextSize(2); // if that doesn't change anywhere else
display.setTextColor(WHITE); // that could be done once in `setup()`
display.setCursor(x, y);
snprintf(txt, sizeof(txt), "%.1f Grad", tempc);
display.print(txt);
display++;
if (display > 3) display = 0;
// individual display pages
switch(display) {
case 0:
case 1: // why is there a second case that does exactly the same?
display.setCursor(x,(y+=20)); // move 20px down in the process
snprintf(txt, sizeof(txt), "%.1f kt", WindSpeedkt);
display.print(txt);
display.setCursor(x,(y+=20)); // move 20px down in the process
snprintf(txt, sizeof(txt), "%d deg", CalDirection);
display.print(txt);
break;
case 2:
case 3: // why is there a second case that does exactly the same?
display.setCursor(x,(y+=20)); // move 20px down in the process
snprintf(txt, sizeof(txt), "%.2f hP", pressurehpa);
display.print(txt);
display.setCursor(x,(y+=20)); // move 20px down in the process
snprintf(txt, sizeof(txt), "%.1f %%", humidity);
display.print(txt);
break;
default:
break;
}
// common to all display pages
display.display();
}
(the individual print blocks could also be unified into a function and/or treated in a loop)
1 Like