Created
October 31, 2025 15:56
-
-
Save maxpromer/cd5a53089bca9f55fe5aaac4d821b555 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include <Arduino.h> | |
| #include <WiFi.h> | |
| #include <ESP32-HUB75-MatrixPanel-I2S-DMA.h> | |
| #include <ESPAsyncWebServer.h> | |
| #include "index.h" | |
| #define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module. | |
| #define PANEL_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module. | |
| #define PANEL_CHAIN 1 // Total number of panels chained one to another | |
| // MatrixPanel_I2S_DMA dma_display; | |
| MatrixPanel_I2S_DMA *dma_display = nullptr; | |
| AsyncWebServer server(80); | |
| unsigned int queue[3] = { 0, 0 }; | |
| bool queue_change_flag = false; | |
| bool show_wifi_connecting = false; | |
| // ---------- Helper to parse channel number from URL ---------- | |
| int parseChannel(String url) { | |
| // Expect URL format: /control/<1-3>/next or /control/<1-3>/back | |
| int firstSlash = url.indexOf('/', 1); // first slash after "/" | |
| int secondSlash = url.indexOf('/', firstSlash + 1); | |
| if (firstSlash < 0 || secondSlash < 0) return -1; | |
| String chStr = url.substring(firstSlash + 1, secondSlash); | |
| int chNumber = chStr.toInt(); | |
| if (chNumber < 1 || chNumber > 3) return -1; | |
| return chNumber - 1; // convert to 0-based index | |
| } | |
| void setup() { | |
| Serial.begin(115200); | |
| // Start WiFi in AP mode | |
| WiFi.mode(WIFI_AP); | |
| WiFi.softAP("ESP32 Queue"); | |
| Serial.print("AP IP address: "); | |
| Serial.println(WiFi.softAPIP()); | |
| // ---------- Routes ---------- | |
| // Serve index page | |
| server.on("/", HTTP_GET, [](AsyncWebServerRequest *request) { | |
| request->send(200, "text/html", index_html); | |
| }); | |
| server.on("/index.html", HTTP_GET, [](AsyncWebServerRequest *request) { | |
| request->send(200, "text/html", index_html); | |
| }); | |
| // Return current queue values as plain JSON array | |
| server.on("/current", HTTP_GET, [](AsyncWebServerRequest *request) { | |
| String json = "[" + String(queue[0]) + "," + String(queue[1]) + "," + String(queue[2]) + "]"; | |
| request->send(200, "application/json", json); | |
| }); | |
| // POST /control/<1-3>/next | |
| server.on("/control/*", HTTP_POST, [](AsyncWebServerRequest *request) { | |
| String url = request->url(); // full path | |
| int idx = parseChannel(url); | |
| if (idx >= 0) { | |
| if (url.endsWith("/next")) queue[idx]++; | |
| else if (url.endsWith("/back")) queue[idx]--; | |
| else { | |
| request->send(404, "application/json", "{\"error\":\"invalid action\"}"); | |
| return; | |
| } | |
| request->send(200, "application/json", String(queue[idx])); | |
| queue_change_flag = true; | |
| } else { | |
| request->send(400, "application/json", "{\"error\":\"invalid channel\"}"); | |
| } | |
| }); | |
| // Start server | |
| server.begin(); | |
| Serial.println("HTTP server started"); | |
| // Display Setup | |
| HUB75_I2S_CFG mxconfig( | |
| PANEL_RES_X, // module width | |
| PANEL_RES_Y, // module height | |
| PANEL_CHAIN // Chain length | |
| ); | |
| dma_display = new MatrixPanel_I2S_DMA(mxconfig); | |
| dma_display->begin(); | |
| dma_display->setBrightness8(90); //0-255 | |
| dma_display->clearScreen(); | |
| dma_display->setTextSize(1); // size 1 == 8 pixels high | |
| dma_display->setTextWrap(false); // Don't wrap at end of line - will do ourselves | |
| queue_change_flag = true; | |
| } | |
| void loop() { | |
| if (queue_change_flag) { | |
| dma_display->fillScreen(dma_display->color444(0, 0, 0)); // เทสีดำทั้งจอ | |
| dma_display->drawRect(0, 0, 11, 11, dma_display->color565(255, 0, 0)); | |
| dma_display->setCursor(3, 2); // กำหนดพิกัดเริ่มวาด (2, 2) | |
| dma_display->setTextSize(1); // กำหนดขนาดตัวอักษร 1 | |
| dma_display->setTextColor(dma_display->color565(255, 0, 0)); // กำหนดสีตัวอักษรสีฟ้า | |
| dma_display->print("1"); // แสดงข้อความ 1 บนหน้าจอ | |
| dma_display->setCursor(15, 2); // กำหนดพิกัดเริ่มวาด (2, 11) | |
| dma_display->printf("%04d", queue[0]); // แสดงหมายเลขคิวช่อง 1 บนหน้าจอ | |
| dma_display->drawRect(0, 11, 11, 11, dma_display->color565(0, 255, 0)); | |
| dma_display->setCursor(3, 13); // กำหนดพิกัดเริ่มวาด (2, 2) | |
| dma_display->setTextSize(1); // กำหนดขนาดตัวอักษร 1 | |
| dma_display->setTextColor(dma_display->color565(0, 255, 0)); // กำหนดสีตัวอักษรสีฟ้า | |
| dma_display->print("2"); // แสดงข้อความ 2 บนหน้าจอ | |
| dma_display->setCursor(15, 13); // กำหนดพิกัดเริ่มวาด (2, 11) | |
| dma_display->printf("%04d", queue[1]); // แสดงหมายเลขคิวช่อง 2 บนหน้าจอ | |
| dma_display->drawRect(0, 22, 11, 11, dma_display->color565(0, 0, 255)); | |
| dma_display->setCursor(3, 24); // กำหนดพิกัดเริ่มวาด (2, 2) | |
| dma_display->setTextSize(1); // กำหนดขนาดตัวอักษร 1 | |
| dma_display->setTextColor(dma_display->color565(0, 0, 255)); // กำหนดสีตัวอักษรสีฟ้า | |
| dma_display->print("3"); // แสดงข้อความ 3 บนหน้าจอ | |
| dma_display->setCursor(15, 24); // กำหนดพิกัดเริ่มวาด (2, 11) | |
| dma_display->printf("%04d", queue[2]); // แสดงหมายเลขคิวช่อง 3 บนหน้าจอ | |
| queue_change_flag = false; | |
| } | |
| delay(50); // หน่วงเวลา 500 ms | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment