代码在下面。我正在将Adafruit Huzzah Feather和Feather翼TFT显示器一起使用。我正在尝试创建一个带有几个按钮的简单GUI。至少据我所知,所显示的初始按钮快如闪电。当我点击触摸屏转到新的“页面”时,我可以看到矩形被绘制了一秒钟,然后使用我正在绘制的新按钮进行绘制。这件事应该这么慢还是我在做一些愚蠢的事情?我什至在使用“更快的” TFT_eSPI库。在其他示例中,例如按钮,显示更新非常快。有什么想法吗?
#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
}
以下是该示例的输出,但我可以发誓即使绘制按钮也要花费半秒钟。真是痛苦!
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
答案 0 :(得分:0)
看完之后,简单的答案是:因为硬件/库太慢了。