🚩Colors aren't accurate. The arduino code works.

This commit is contained in:
Boyan 2023-09-09 21:46:39 +02:00
parent 0c7668e04f
commit 47d4ab014b

View File

@ -6,22 +6,43 @@
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h> #include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
#include <WiFi.h> #include <WiFi.h>
#include <HTTPClient.h> #include <HTTPClient.h>
#include <Arduino_JSON.h>
#define REFRESH 10 // Seconds until refresh
#define PANEL_RES_X 64 // Number of pixels wide of each INDIVIDUAL panel module. #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_RES_Y 32 // Number of pixels tall of each INDIVIDUAL panel module.
#define PANEL_CHAIN 1 // Total number of panels chained one to another #define PANEL_CHAIN 1 // Total number of panels chained one to another
//MatrixPanel_I2S_DMA dma_display; //MatrixPanel_I2S_DMA dma_display;
MatrixPanel_I2S_DMA *dma_display = nullptr; 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); dma_display->drawPixel(x, y, color);
} }
// Replace with your network credentials // Replace with your network credentials
const char* ssid = "ssid"; const char* ssid = "SSID";
const char* password = "password"; const char* password = "PASSWORD";
String serverName = "https://your-domain.com/board/json/";
void initWiFi() { void initWiFi() {
WiFi.mode(WIFI_STA); WiFi.mode(WIFI_STA);
@ -34,11 +55,11 @@ void initWiFi() {
Serial.println(WiFi.localIP()); Serial.println(WiFi.localIP());
} }
String serverName = "https://changethis.com/board/json/";
void setup() { void setup() {
Serial.begin(9600);
initWiFi(); initWiFi();
// Module configuration // Module configuration
HUB75_I2S_CFG mxconfig( HUB75_I2S_CFG mxconfig(
@ -53,7 +74,7 @@ void setup() {
dma_display->begin(); dma_display->begin();
dma_display->setBrightness8(90); //0-255 dma_display->setBrightness8(90); //0-255
dma_display->clearScreen(); dma_display->clearScreen();
// fill the screen with 'black' // fill the screen with 'black'
dma_display->fillScreen(dma_display->color444(0, 0, 0)); dma_display->fillScreen(dma_display->color444(0, 0, 0));
@ -69,28 +90,28 @@ unsigned long lastTime = 0;
unsigned long timerDelay = 5000; unsigned long timerDelay = 5000;
void loop() { void loop() {
if ((millis() - lastTime) > timerDelay) { if ((millis() - lastTime) > timerDelay) {
//Check WiFi connection status //Check WiFi connection status
if(WiFi.status()== WL_CONNECTED){ String payload = "null";
if (WiFi.status() == WL_CONNECTED) {
HTTPClient http; HTTPClient http;
String serverPath = serverName; String serverPath = serverName;
// Your Domain name with URL path or IP address with path // Your Domain name with URL path or IP address with path
http.begin(serverPath.c_str()); http.begin(serverPath.c_str());
// If you need Node-RED/server authentication, insert user and password below // If you need Node-RED/server authentication, insert user and password below
//http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD"); //http.setAuthorization("REPLACE_WITH_SERVER_USERNAME", "REPLACE_WITH_SERVER_PASSWORD");
// Send HTTP GET request // Send HTTP GET request
int httpResponseCode = http.GET(); int httpResponseCode = http.GET();
if (httpResponseCode>0) { if (httpResponseCode > 0) {
Serial.print("HTTP Response code: "); Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode); Serial.println(httpResponseCode);
String payload = http.getString(); payload = http.getString();
Serial.println(payload);
} }
else { else {
Serial.print("Error code: "); Serial.print("Error code: ");
@ -104,13 +125,32 @@ void loop() {
WiFi.reconnect(); WiFi.reconnect();
} }
lastTime = millis(); 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);
} }