#include #include #include // 你之前已经装好的屏幕库 // ====== WiFi 信息 ====== const char* ssid = "SEEED-MKT"; const char* password = "edgemaker2023"; // ====== 创建对象 ====== WebServer server(80); TFT_eSPI tft = TFT_eSPI(); // ====== 当前显示内容 ====== String currentText = "Hello"; // ====== 网页内容 ====== String getHTML() { String html = ""; html += "XIAO Control"; html += ""; html += "

控制屏幕显示

"; html += "

当前内容: " + currentText + "

"; html += "

"; html += "

"; html += ""; html += ""; return html; } // ====== 屏幕显示函数 ====== void drawText(String text) { tft.fillScreen(TFT_BLACK); tft.setTextColor(TFT_RED, TFT_BLACK); tft.setTextSize(3); tft.setCursor(20, 60); tft.println(text); } // ====== 路由 ====== void handleRoot() { server.send(200, "text/html", getHTML()); } void handleFu() { currentText = "FU"; drawText("FU"); // 中文可能不显示,先用FU测试 server.send(200, "text/html", getHTML()); } void handleTemp() { currentText = "Temp:25C"; drawText("Temp:25C"); server.send(200, "text/html", getHTML()); } void handleHello() { currentText = "Hello"; drawText("Hello"); server.send(200, "text/html", getHTML()); } // ====== 初始化 ====== void setup() { Serial.begin(115200); // 屏幕初始化 tft.init(); tft.setRotation(0); drawText("Starting..."); // WiFi连接 WiFi.begin(ssid, password); Serial.print("Connecting"); while (WiFi.status() != WL_CONNECTED) { delay(500); Serial.print("."); } Serial.println("\nConnected!"); Serial.println(WiFi.localIP()); drawText("Connected!"); // 路由绑定 server.on("/", handleRoot); server.on("/f", handleFu); server.on("/temp", handleTemp); server.on("/hello", handleHello); server.begin(); } // ====== 主循环 ====== void loop() { server.handleClient(); }