Hi. I have a 3.5" 480x320 TFT display with SPI connection to an ESP32. I'm using TFT_eSPI library to communicate with display and Setup 21 but with DC connected to GPIO16. I am drawing a TFT_GOLD line using drawLine. After that, I'm drawing another line but TFT_TRANSPARENT to clear that line. My problem is that a green-ish trace is left behind as you can see in images. I tried using TFT_BLACK but it doesn't do anything. here is my code:
#include <TFT_eSPI.h>
#include <SPI.h>
#include "dial.h"
TFT_eSPI tft = TFT_eSPI();
TFT_eSprite needle = TFT_eSprite(&tft);
TFT_eSprite label = TFT_eSprite(&tft);
void setup() {
Serial.begin(115200);
tft.init();
tft.setRotation(3);
tft.fillScreen(TFT_BLACK);
tft.setSwapBytes(true);
tft.pushImage(0,120,480,80,dial);
needle.setColorDepth(8);
needle.createSprite(320,50);
}
int getTopX(int speed) {
double tmp = speed * 290;
int topX = (int)(tmp/60 + 0.5);
return topX;
}
int getBottomX(int speed) {
double tmp = speed * 160;
int topX = (int)(tmp/60 + 65.5);
return topX;
}
void drawNeedle(int last_speed, int speed) {
// clearing last line:
int ltopx = getTopX(last_speed);
int lbtmx = getBottomX(last_speed);
needle.drawLine(lbtmx,50,ltopx,0, TFT_TRANSPARENT);
needle.setTextColor(TFT_TRANSPARENT);
needle.drawString(String(last_speed), 40,60, 7);
needle.setTextColor(TFT_WHITE);
needle.drawString(String(speed),40,60,7);
// drawing new line:
int topx = getTopX(speed);
int btmx = getBottomX(speed);
needle.drawLine(btmx,50,topx,0,TFT_WHITE);
needle.pushSprite(90,200, TFT_BLACK);
}
int lspeed=0;
void loop() {
for (int speed= 0; speed < 61; speed++) {
int start = millis();
drawNeedle(lspeed, speed);
lspeed = speed;
Serial.println(String(millis() - start));
}
}
the problem i have is that drawing each line/speed should not take mor than 80 ms. currently it takes around 35, so everything is good (speed number not showing is not a problem as it is drawn outside of sprite dimensions. I will fix that later). here are the images:
TFT_TRANSPARENT (Don't mind double lines. That's because i took this image while it was drawing a new line.):
TFT_BLACK (IRL all lines are same color IDK why it is like this in the image: