- Sun Oct 18, 2020 2:22 am
#89124
I'm making a program that can dynamically push text or color or brightness to a neopixel matrix. This code works, but after about 5min the ESP8266 resets all of a sudden with no reason. Also, unrelated, I can't access the serial monitor for anything.
Code: Select all#include <ESP8266WiFi.h>
#include <ESP8266WebServer.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
static const uint8_t gif[] PROGMEM = {
0x47, 0x49, 0x46, 0x38, 0x39, 0x61, 0x1b, 0x00, 0x05,
0x00, 0xf0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x00, 0x21, 0xf9, 0x04, 0x01, 0x00, 0x00, 0x01, 0x00,
0x2c, 0x00, 0x00, 0x00, 0x00, 0x1b, 0x00, 0x05, 0x00,
0x00, 0x02, 0x1a, 0x44, 0x0c, 0x79, 0x9a, 0xb8, 0x8e,
0x60, 0x98, 0x86, 0xce, 0x83, 0x65, 0x8b, 0xfc, 0xe5,
0x2a, 0x65, 0x97, 0x65, 0x85, 0x63, 0xe3, 0xa1, 0xaa,
0x08, 0x15, 0x00, 0x3b,
};
const char* ssid = "matrix";
const char* password = "12345678";
ESP8266WebServer server(80);
#define PIN D4
bool current_changed = false;
String current_text = "HELLO";
int current_color[3] = {255, 0, 0};
int current_brightness = 50;
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_BOTTOM + NEO_MATRIX_RIGHT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
void setup() {
WiFi.softAP(ssid, password);
IPAddress local_ip(10,0,1,1);
IPAddress gateway(10,0,1,1);
IPAddress subnet(255,255,0,0);
WiFi.softAPConfig(local_ip, gateway, subnet);
server.on("/", []() {
char gif_colored[sizeof(gif)];
memcpy_P(gif_colored, gif, sizeof(gif));
server.sendHeader("Commmand-Response", current_text + "~" + current_color[0] + "," + current_color[1] + "," + current_color[2] + "~" + current_brightness);
server.send(200, "image/gif", gif_colored, sizeof(gif_colored));
});
server.on("/c2c", []() {
char gif_colored[sizeof(gif)];
memcpy_P(gif_colored, gif, sizeof(gif));
server.sendHeader("Access-Control-Allow-Origin", "*");
if(server.hasArg("cmd")) {
if(server.arg("cmd") == "text") {
current_text = server.arg("value");
current_changed = true;
server.sendHeader("Commmand-Response", current_text);
server.send(200, "image/gif", gif_colored, sizeof(gif_colored));
}
if(server.arg("cmd") == "color") {
int red = server.arg("red").toInt();
int green = server.arg("green").toInt();
int blue = server.arg("blue").toInt();
current_color[0] = red;
current_color[1] = green;
current_color[2] = blue;
matrix.setTextColor(
matrix.Color(current_color[0], current_color[1], current_color[2])
);
server.sendHeader("Commmand-Response",
server.arg("red") + "," +
server.arg("green") + "," +
server.arg("blue")
);
server.send(200, "image/gif", gif_colored, sizeof(gif_colored));
}
if(server.arg("cmd") == "brightness") {
current_brightness = server.arg("value").toInt();
matrix.setBrightness(current_brightness);
server.sendHeader("Commmand-Response", server.arg("value"));
server.send(200, "image/gif", gif_colored, sizeof(gif_colored));
}
}
});
server.onNotFound([]() {
char gif_colored[sizeof(gif)];
memcpy_P(gif_colored, gif, sizeof(gif));
server.send(200, "image/gif", gif_colored, sizeof(gif_colored));
});
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(5);
matrix.setTextColor(
matrix.Color(255, 0, 0)
);
server.begin();
}
int z = 0;
int x = matrix.width();
int pass = 0;
int pixels = 0;
void loop() {
server.handleClient();
pixels = ((current_text.length() * 6) + 10) * -1;
if(current_changed) {
x = matrix.width();
current_changed = false;
}
matrix.fillScreen(0);
matrix.setCursor(x, 0);
matrix.print(current_text);
if(--x < pixels) {
x = matrix.width();
}
matrix.show();
delay(100);
}