Hello, this is my first time posting and as well as working with Arduino LCD Display.
I am trying to create this status update screen, where if serial communication is established the screen will read "ONLINE" and if its not then "OFFLINE".
void systemconnection(boolean online){
int maxStringLength = 158; //String Pixel Width
int maxStringWidth = 8; //String Pixel Height
tft.fillRect(50, 50, maxStringLength, maxStringWidth,ILI9341_BLACK); //draw over previous status update
tft.setCursor(50,50);
if (online){
//status online
tft.setTextColor(ILI9341_WHITE);
tft.print("CONNECTION: ");
tft.setTextColor(ILI9341_GREEN);
tft.print("ONLINE");
}
else if (!online){
//status online
tft.setTextColor(ILI9341_WHITE);
tft.print("CONNECTION: ");
tft.setTextColor(ILI9341_RED);
tft.print("OFFLINE");
}
}
tft.fillRect(50, 50, maxStringLength, maxStringWidth,ILI9341_BLACK); //draw over previous
The problem here is that when communication is restablished or disconnected the print statements overwrite each other, I call this function here,
void gloveInterface() {
// Set Strings
int receivedData[5];
tft.fillScreen(ILI9341_BLACK);
String thumb = "Thumb: ";
String index = "Index: ";
String middle = "Middle: ";
String ring = "Ring: ";
String pinky = "Pinky: ";
while (true) {
if (Serial.available()) {
//Read the received data
Serial.readBytes((byte*)receivedData, sizeof(receivedData));
// SYSTEM ONLINE
systemconnection(true);
// Clear region for updated data
tft.fillRect(195, centerTextHeight(-40) - 10, 60, 20, ILI9341_BLACK);
tft.fillRect(195, centerTextHeight(-20) - 10, 60, 20, ILI9341_BLACK);
tft.fillRect(195, centerTextHeight(0) - 10, 60, 20, ILI9341_BLACK);
tft.fillRect(195, centerTextHeight(20) - 10, 60, 20, ILI9341_BLACK);
tft.fillRect(195, centerTextHeight(40) - 10, 60, 30, ILI9341_BLACK);
// Thumb
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(centerTextWidth(thumb, 12), centerTextHeight(40));
tft.println(thumb + String(receivedData[0]/256));
// Index
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(centerTextWidth(index, 12), centerTextHeight(-40));
tft.println(index + String(receivedData[1]/256));
// Middle
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(centerTextWidth(middle, 12), centerTextHeight(-20));
tft.println(middle + String(receivedData[2]/256));
// Ring
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(centerTextWidth(ring, 12), centerTextHeight(0));
tft.println(ring + String(receivedData[3]/256));
// Pinky
tft.setTextColor(ILI9341_WHITE);
tft.setCursor(centerTextWidth(pinky, 12), centerTextHeight(20));
tft.println(pinky + String(receivedData[4]/256));
}else{
systemconnection(false);
}
}
}
In this line I am trying to overwrite what was previously on display but would the lcd.clear() function work better. Is there better way I can update information without the previous message interfereing.