I'm learning how to use my touch screen by just messing around. Right now, I'm trying to create a timer and have so that when I tap the screen, it changes color. My issue right now is with the delay in the loop. Without it, the text color prints and clears so fast the screen is just blank, but with it a screen tap only registers if you tap it outside of the delay. Any advice on an algorithm that will allow me to get rid of the delay and keep the timer going?
unsigned long startMillis;
unsigned long currentMillis;
unsigned long timerMillis;
unsigned long oldMillis;
unsigned int screenColor;
void setup(void)
{
Serial.begin(9600);
tft.begin();
startMillis = millis()/1000;
currentMillis = millis()/1000;
tft.fillScreen(ILI9341_BLACK);
screenColor = 0;
tft.setRotation(1);
}
void loop()
{
// Retrieve a point
currentMillis = millis()/1000;
timerMillis = currentMillis - startMillis;
TSPoint p = ts.getPoint();
tft.setCursor(100, 80);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(10);
tft.println(timerMillis);
delay(100);
tft.setCursor(100, 80);
tft.setTextColor(ILI9341_BLACK);
tft.setTextSize(10);
tft.println(timerMillis);
// See if there's any touch data for us
if (p.z > MINPRESSURE && p.z < MAXPRESSURE)
{
if (screenColor == 0)
{
tft.fillScreen(ILI9341_BLUE);
screenColor = 1;
}
else
{
tft.fillScreen(ILI9341_BLACK);
screenColor = 0;
}
}
}