From 47d4ab014be7052a0a64cdad8d9c8ccfac66ef6c Mon Sep 17 00:00:00 2001 From: Boyan Date: Sat, 9 Sep 2023 21:46:39 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A9Colors=20aren't=20accurate.=20The?= =?UTF-8?q?=20arduino=20code=20works.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/arduino/text_display/text_display.ino | 88 ++++++++++++++++------- 1 file changed, 64 insertions(+), 24 deletions(-) diff --git a/src/arduino/text_display/text_display.ino b/src/arduino/text_display/text_display.ino index a482eea..4f24e9d 100644 --- a/src/arduino/text_display/text_display.ino +++ b/src/arduino/text_display/text_display.ino @@ -6,22 +6,43 @@ #include #include #include +#include - +#define REFRESH 10 // Seconds until refresh #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; -void putPixel(int16_t x, int16_t y, uint16_t color) { + + +int hexToRGB(String hex) { + + // TODO: Fix the colors not being accurate + // Remove the '#' from the start + hex.remove(0, 1); + + // Extract and convert the red, green, and blue components + uint8_t r = strtol(hex.substring(0, 2).c_str(), NULL, 16); + uint8_t g = strtol(hex.substring(2, 4).c_str(), NULL, 16); + uint8_t b = strtol(hex.substring(4, 6).c_str(), NULL, 16); + + return dma_display->color565(r, g, b); + +} + + +// Pixel putting +void putPixel(int16_t x, int16_t y, int color) { dma_display->drawPixel(x, y, color); } // Replace with your network credentials -const char* ssid = "ssid"; -const char* password = "password"; +const char* ssid = "SSID"; +const char* password = "PASSWORD"; +String serverName = "https://your-domain.com/board/json/"; void initWiFi() { WiFi.mode(WIFI_STA); @@ -34,11 +55,11 @@ void initWiFi() { Serial.println(WiFi.localIP()); } -String serverName = "https://changethis.com/board/json/"; void setup() { + Serial.begin(9600); initWiFi(); // Module configuration HUB75_I2S_CFG mxconfig( @@ -53,7 +74,7 @@ void setup() { dma_display->begin(); dma_display->setBrightness8(90); //0-255 dma_display->clearScreen(); - + // fill the screen with 'black' dma_display->fillScreen(dma_display->color444(0, 0, 0)); @@ -69,28 +90,28 @@ unsigned long lastTime = 0; unsigned long timerDelay = 5000; void loop() { - - if ((millis() - lastTime) > timerDelay) { + + if ((millis() - lastTime) > timerDelay) { //Check WiFi connection status - if(WiFi.status()== WL_CONNECTED){ + String payload = "null"; + if (WiFi.status() == WL_CONNECTED) { HTTPClient http; String serverPath = serverName; - + // Your Domain name with URL path or IP address with path http.begin(serverPath.c_str()); - + // If you need Node-RED/server authentication, insert user and password below //http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD"); - + // Send HTTP GET request int httpResponseCode = http.GET(); - - if (httpResponseCode>0) { + + if (httpResponseCode > 0) { Serial.print("HTTP Response code: "); Serial.println(httpResponseCode); - String payload = http.getString(); - Serial.println(payload); + payload = http.getString(); } else { Serial.print("Error code: "); @@ -104,13 +125,32 @@ void loop() { WiFi.reconnect(); } lastTime = millis(); + + if (payload != "null") { + JSONVar board = JSON.parse(payload); + if (JSON.typeof(board) == "undefined") { + Serial.println("Parsing failed!"); + return; + } + // Parse JSON + for (int y = 0; y < PANEL_RES_Y; y++) { + for (int x = 0; x < PANEL_RES_X; x++) { + String color = board[String(y)][x]; + + int colorize; + if (color.length() < 1) { + colorize = dma_display->color444(0, 0, 0); + } + else { + colorize = hexToRGB(color); + } + putPixel(x, y, colorize); + } + } + } + + } -} - // animate by going through the colour wheel for the first two lines - drawText(wheelval); - wheelval +=1; - delay(20); - - + delay(REFRESH * 100); }