Code is below. I'm using the Adafruit Huzzah Feather with the Feather wing TFT display. I'm trying to create a simple GUI that has a few buttons on it. The initial buttons being displayed is lightning quick, at least as far as I can tell. When I hit the touchscreen to go to a new "page" I can see the rectangle being drawn over a second and then the same thing with the new button that I'm drawing. Is this thing supposed to be this slow or am I doing something that stupid? I'm even using the "faster" TFT_eSPI library. With other examples, like a push button the display updates really quick. Any ideas?
#include <SPI.h>
#include <Wire.h> // this is needed even tho we aren't using it
#include <ESP8266WiFi.h>
#include "FS.h"
#include <TFT_eSPI.h> // Core graphics library
#include <Adafruit_STMPE610.h> // Touchscreen Controller
#define CALIBRATION_FILE "/TouchCalData3"
#define REPEAT_CAL false
#define TS_MINX 3800
#define TS_MAXX 100
#define TS_MINY 100
#define TS_MAXY 3750
const char *ssid = "AP"; // The name of the Wi-Fi network that will be created
const char *password = "changeme"; // The password required to connect to it, leave blank for an open network
Adafruit_STMPE610 ts = Adafruit_STMPE610(16);
int currentPage = 0;
bool allSelected = true;
TFT_eSPI tft = TFT_eSPI(); // Invoke library, pins defined in User_Setup.h
void setup(void) {
Serial.begin(115200);
delay(10);
if (!ts.begin()) {
Serial.println("Couldn't start touchscreen controller");
while (1);
}
Serial.println("Touchscreen started");
tft.init();
tft.setRotation(0);
setupAp();
drawHomePage();
}
void drawHomePage() {
wipe();
Serial.println("Drawing HP");
long time1 = millis();
tft.drawRoundRect(10, 10, 220, 145, 7, ILI9341_WHITE);
tft.drawCentreString("LIGHTS", 120, 60, 2);
tft.drawRoundRect(10, 165, 220, 145, 7, ILI9341_YELLOW);
tft.setTextColor(ILI9341_YELLOW);
tft.drawCentreString("GAUGES", 120, 220, 2);
long time2 = millis();
long result = time2 - time1;
Serial.print("HP Took: "); Serial.println(result);
}
void drawLightsHomePage() {
wipe();
Serial.println("Drawing Lights");
long time1 = millis();
if(allSelected) {
tft.fillRect(10, 10, 58, 52, ILI9341_WHITE);
tft.setTextColor(ILI9341_BLACK);
tft.drawCentreString("All", 34, 20, 2);
}
else {
tft.drawRect(10, 10, 68, 52, ILI9341_WHITE);
tft.setTextColor(ILI9341_WHITE);
tft.drawCentreString("All", 34, 60, 2);
}
long time2 = millis();
long result = time2 - time1;
Serial.print("Lights Took: "); Serial.println(result);
}
void wipe() {
long time1 = millis();
Serial.println("Wiping screen");
tft.fillRect(0, 0, 240, 320, ILI9341_BLACK);
long time2 = millis();
long result = time2 - time1;
Serial.print("Wiping took: "); Serial.println(result);
}
void loop() {
// Retrieve a point
TS_Point p = ts.getPoint();
if (ts.bufferSize()) {
p = ts.getPoint();
} else {
p.x = p.y = p.z = -1;// this is our way of tracking touch 'release'!
}
if (p.z != -1) {
tft.fillCircle(p.x, p.y, 2, TFT_WHITE);
p.x = map(p.x, TS_MINX, TS_MAXX, 0, tft.width());
p.y = map(p.y, TS_MINY, TS_MAXY, 0, tft.height());
Serial.print("("); Serial.print(p.x); Serial.print(", ");
Serial.print(p.y); Serial.print(", ");
Serial.print(p.z); Serial.println(") ");
if(currentPage == 0) {
if(p.y < 160) {
Serial.println("Hit Button");
currentPage = 1;
drawLightsHomePage();
}
else if(p.y > 160 && p.y < 320) {
}
}
}
}
void setupAp() {
Serial.println('\n');
WiFi.softAP(ssid, password); // Start the access point
Serial.print("Access Point \"");
Serial.print(ssid);
Serial.println("\" started");
Serial.print("IP address:\t");
Serial.println(WiFi.softAPIP()); // Send the IP address of the ESP8266 to the computer
}
Sample output of the times is below, but I could swear even drawing the button take a good half a second. It's agony!
Wiping screen
Wiping took: 48
Drawing HP
HP Took: 6
(109, 111, 50)
Hit Button
Wiping screen
Wiping took: 1234
Drawing Lights
Lights Took: 52
After reading around the simple answer is: Because the hardware/library is that slow.