I'm working on an IOT temperature sensor where I would like to update the temperature shown on the display separate from a "statusline" that shows other information. If using the clearDisplay() function and then printing all information to the display, everything seems to work fine apart from the slightly annoying screen flicker observed when the screen updates.
I have tried separating temperature and status display in two separate functions, but without calling the clearDisplay() function it only seems to just add to the current info shown. I read a post on the arduino forum somewhere saying one could just overwrite parts of the display with spaces before writing new information to the display, but this doesn't seem to have the desired effect either.
The behaviour experienced before and after updating the display: And here are some 'dummy code' of the code used for displaying information on the display, since in the real
project files I have put all the code for using the display in its own c++ class.
Code: Select all
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SH110X.h>
Adafruit_SH1107 display = Adafruit_SH1107(64, 128, &Wire);
int count = 1;
bool status = true;
void setup() {
Serial.begin(115200);
display.begin(0x3C, true);
delay(250);
display.clearDisplay();
display.setRotation(1);
display.setTextColor(SH110X_WHITE);
display.setTextSize(1);
display.setCursor(0, 0);
display.display();
}
void displayTemperature(double t){
display.setTextSize(1);
display.setCursor(0, 0);
display.print("Temperature:");
display.setTextSize(2);
display.setCursor(10, 20);
display.print(t);
display.display();
}
void displayStatus(bool s1, int s2){
display.setTextSize(1);
display.setCursor(0, 48);
display.print("---------------------");
display.print("WiFi: ");
display.print(s1);
display.print(" Sent:");
display.print(s2);
display.display();
}
void clearStatus(){
display.setTextSize(1);
display.setCursor(0, 48);
display.print("---------------------");
display.print(" ");
display.display();
}
void loop() {
double temp = double(random(20));
displayTemperature(temp);
displayStatus(status, count);
delay(1000);
count++;
status = !status;
Serial.print("Count: "); Serial.println(count);
Serial.print("Status: "); Serial.println(status);
clearStatus();
delay(1000);
yield();
}
newbie errors, so I would really appreciate some experienced feedback on this.
Thanks in advance
Rune