Hello!
I am making a humidity and temp reading device witch both is going to send data to a MySensors gateway and display the information in a graph on a TFT screen.
The code is not complete yet, but I am starting to see that there will be an ugly presentation of the graph being drawn on the screen.
From the beginning I was using a Arduino Due, but the MySensors lib do not compile when I'm using the Due. So I had to switch to a Arduino Mega 2560 and then I saw the ugly presentation.
I am planing to read the temp and humidity values between once every 5 second to once every 30 min, depending how the settings is.
Is there anyway to optimize the code or is it possible to draw a "back buffer" and just switch the "old screen" against a new?
void screenUpd() {
TFTscreen.fillScreen(0x0000); //Clear screen to black
TFTscreen.setTextColor(ST7735_GREEN);
TFTscreen.setCursor(0, 0);
TFTscreen.print("Humid %");
TFTscreen.setCursor(0, 12);
TFTscreen.print((float)DHT.humidity);
TFTscreen.setTextColor(ST7735_RED);
TFTscreen.setCursor(45, 0);
TFTscreen.print("Temp");
TFTscreen.setCursor(45, 12);
TFTscreen.print((float)DHT.temperature);
for (count=wTFT-2; count>=2; count--) //Graph
{
TFTscreen.drawLine(count, map(sensorArray[count], 100, 0, 26, 125), count-1, map(sensorArray[count-1], 100,0, 25, 126), ST7735_GREEN);
TFTscreen.drawLine(count, map(sensorArray2[count], 60, -20, 26, 125), count-1, map(sensorArray2[count-1], 60, -20, 25, 126), ST7735_RED);
}
if (intersectEn == 1) { //Draw Intersection if enabled.
TFTscreen.setTextColor(ST7735_BLUE);
TFTscreen.setCursor(80, 0);
TFTscreen.print("Intersection");
TFTscreen.setTextColor(ST7735_RED);
TFTscreen.setCursor(105, 12);
TFTscreen.print("C");
TFTscreen.setTextColor(ST7735_GREEN);
TFTscreen.setCursor(150, 12);
TFTscreen.print("%");
TFTscreen.setTextColor(ST7735_RED);
TFTscreen.setCursor(85, 12);
TFTscreen.print(sensorArray2[intersect]);
TFTscreen.setTextColor(ST7735_GREEN);
TFTscreen.setCursor(130, 12);
TFTscreen.print(sensorArray[intersect]);
TFTscreen.drawLine(intersect, 26, intersect, 125, ST7735_WHITE);
}
TFTscreen.drawRect(0, 25, 160, 102, ST7735_WHITE); //Border
TFTscreen.drawLine(1, map(50, 100, 0, 26, 125), 3, map(50, 100, 0, 26, 125), ST7735_GREEN); //Index dot
TFTscreen.drawLine(158, map(0, 60, -20, 26, 125), 156, map(0, 60, -20, 26, 125), ST7735_RED);
}
Thanks in advance.
BR Tim
Edit::
Forgot to mention that I am using this libs.
#include <Adafruit_GFX.h>
#include <gfxfont.h>
#include <Adafruit_ST7735.h>
