🚩Colors aren't accurate. The arduino code works.
This commit is contained in:
parent
0c7668e04f
commit
47d4ab014b
@ -6,8 +6,9 @@
|
||||
#include <ESP32-HUB75-MatrixPanel-I2S-DMA.h>
|
||||
#include <WiFi.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_Y 32 // Number of pixels tall of each INDIVIDUAL panel module.
|
||||
#define PANEL_CHAIN 1 // Total number of panels chained one to another
|
||||
@ -15,13 +16,33 @@
|
||||
//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(
|
||||
@ -72,7 +93,8 @@ void loop() {
|
||||
|
||||
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;
|
||||
@ -86,11 +108,10 @@ void loop() {
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
// animate by going through the colour wheel for the first two lines
|
||||
drawText(wheelval);
|
||||
wheelval +=1;
|
||||
|
||||
delay(20);
|
||||
|
||||
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
delay(REFRESH * 100);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user