Skip to content
Snippets Groups Projects
Commit 7d77e685 authored by Stefan Schueller's avatar Stefan Schueller
Browse files

Updates

parent af864d57
No related branches found
No related tags found
No related merge requests found
......@@ -13,6 +13,7 @@
### Required
- ESP32 (LOLIN32)
- 8x8 LED matrix
- Reset Button
### Optional
- Light Sensor
......
......@@ -7,16 +7,26 @@
// the digital pin for controlling the WS2812 LED Matrix
#define LED_PIN 3
#define DATA_PIN 3
#define COLOR_ORDER GRB
#define CHIPSET WS2811
#define BRIGHTNESS 16
// data directory (no trailing slash!)
#define GIF_DIRECTORY "/gifs"
#define GIF_UPLOAD_DIRECTORY "/gifs/"
// default brightness
#define BRIGHTNESS 16
// light sensor PIN, comment out of not connected
#define LIGHTSENSORPIN A0
// how long to display an animation
#define DISPLAY_TIME_SECONDS 10
// Wifi access point name
#define WIFIAPNAME "LEDMatrix"
// Time to wait (in seconds) for connection to portal
#define WIFIPORTALTIMEOUT 180
//
#define SET_BUTTON GPIO_NUM_15
#endif
\ No newline at end of file
......@@ -12,7 +12,6 @@
#include <EasyButton.h>
// Private Libs
#include <GifDecoder.h>
#include <FilenameFunctions.h>
......@@ -27,13 +26,15 @@ boolean ready = false;
File fileSave;
DNSServer dns;
EasyButton button(GPIO_NUM_15);
EasyButton button(SET_BUTTON);
extern StringArray fileList;
const uint8_t kMatrixWidth = MATRIX_WIDTH;
const uint8_t kMatrixHeight = MATRIX_HEIGHT;
const String upload_directory = String(GIF_DIRECTORY) + "/";
#define NUMMATRIX (kMatrixWidth * kMatrixHeight)
CRGB leds[NUMMATRIX];
......@@ -51,7 +52,7 @@ static void handle_update_progress_cb(AsyncWebServerRequest *request, String fil
if (!index)
{
Serial.println("Begin upload");
fileSave = SPIFFS.open(GIF_UPLOAD_DIRECTORY + filename, FILE_WRITE);
fileSave = SPIFFS.open(upload_directory + filename, FILE_WRITE);
}
if (fileSave.write(data, len) != len)
......@@ -90,14 +91,14 @@ void matrix_clear()
void display_scrollText(String text)
{
uint8_t textWidth = text.length() * kMatrixWidth;
int16_t textWidth = text.length() * kMatrixWidth;
//uint8_t size = max(int(kMatrixWidth / 8), 1);
matrix_clear();
matrix->setTextWrap(false); // we don't wrap text so it scrolls nicely
matrix->setTextSize(1);
matrix->setRotation(0);
for (int8_t x = kMatrixWidth; x >= -(textWidth); x--)
for (int16_t x = kMatrixWidth; x >= -(textWidth); x--)
{
yield();
matrix_clear();
......@@ -107,10 +108,6 @@ void display_scrollText(String text)
matrix->show();
delay(100);
}
// matrix->setRotation(0);
// matrix->setCursor(0, 0);
// matrix->show();
}
String imageElement(String imagePath, int imageId)
......@@ -179,22 +176,34 @@ String processor(const String &var)
return String();
}
void onPressedCallback()
void configModeCallback(AsyncWiFiManager *wifiManager)
{
Serial.println("Button Press");
}
// void configModeCallback(AsyncWiFiManager *wifiManager)
// {
matrix->clear();
Serial.println("Entered config mode");
Serial.println(WiFi.softAPIP());
// matrix->clear();
display_scrollText(String("Connect to: " + wifiManager->getConfigPortalSSID()));
display_scrollText(String("Browse to: " + WiFi.softAPIP()));
}
// Serial.println("Entered config mode");
// Serial.println(WiFi.softAPIP());
void resetWifiConfig()
{
Serial.println("Wifi Settings reset");
wifiManager.resetSettings();
WiFi.disconnect(false, true);
WiFi.begin("0", "0");
WiFi.persistent(false); // Do not memorise new connections
//ESP.flashEraseSector(0x3fe);
Serial.println("Rebooting in 10 seconds");
delay(10000);
ESP.restart();
}
// //display_scrollText(String("Connect to: " + wifiManager->getConfigPortalSSID()));
// //display_scrollText(String("Browse to: " + WiFi.softAPIP()));
// }
void onPressedCallback()
{
Serial.println("Button Press");
resetWifiConfig();
}
void setupServer()
{
......@@ -208,16 +217,7 @@ void setupServer()
});
server.on("/reset", HTTP_GET, [](AsyncWebServerRequest *request) {
Serial.println("Wifi Settings reset");
wifiManager.resetSettings();
WiFi.disconnect(false, true);
WiFi.begin("0", "0");
WiFi.persistent(false); // Do not memorise new connections
//ESP.flashEraseSector(0x3fe);
Serial.println("Rebooting in 10 seconds");
delay(10000);
// wifiManager.autoConnect();
ESP.restart();
resetWifiConfig();
});
server.on("/set", HTTP_GET, [](AsyncWebServerRequest *request) {
......@@ -233,6 +233,14 @@ void setupServer()
}
});
server.on("/ajax-brightness", HTTP_GET, [](AsyncWebServerRequest *request) {
return String(light);
request->send(200, contentType, content);
});
server.on("/delete", HTTP_GET, [](AsyncWebServerRequest *request) {
if (request->hasParam("filename"))
{
......@@ -260,7 +268,6 @@ void setupServer()
server.serveStatic("/", SPIFFS, "/"); //.setDefaultFile("index.htm");
server.begin();
}
void setup()
......@@ -275,21 +282,6 @@ void setup()
Serial.begin(115200);
//vTaskDelete(DrawLEDsHandle);
// WiFi.mode(WIFI_STA);
// WiFi.begin(ssid, password);
// if (WiFi.waitForConnectResult() != WL_CONNECTED)
// {
// Serial.printf("WiFi Failed!\n");
// return;
// }
// Serial.print("IP Address: ");
// Serial.println(WiFi.localIP());
// Serial.print("Hostname: ");
// Serial.println(WiFi.getHostname());
SPIFFS.begin();
decoder.setScreenClearCallback(screenClearCallback);
decoder.setUpdateScreenCallback(updateScreenCallback);
......@@ -302,12 +294,13 @@ void setup()
num_files = enumerateGIFFiles(GIF_DIRECTORY, false);
#ifdef LIGHTSENSORPIN
pinMode(LIGHTSENSORPIN, INPUT);
#endif
//wifiManager.setAPCallback(configModeCallback);
wifiManager.autoConnect("LEDMatrix");
wifiManager.setConfigPortalTimeout(180);
wifiManager.setAPCallback(configModeCallback);
wifiManager.autoConnect(WIFIAPNAME);
wifiManager.setConfigPortalTimeout(WIFIPORTALTIMEOUT);
setupServer();
}
......@@ -320,8 +313,9 @@ void loop()
if (!ready)
{
ready = true;
// String currentIp = WiFi.localIP().toString();
// display_scrollText(String("Browse to: ") + currentIp);
String currentIp = WiFi.localIP().toString();
display_scrollText(String(currentIp));
display_scrollText(String(currentIp));
}
else
{
......@@ -342,50 +336,22 @@ void loop()
// Calculate time in the future to terminate animation
futureTime = millis() + (DISPLAY_TIME_SECONDS * 1000);
}
}
// auto brightness
int light_value = analogRead(LIGHTSENSORPIN);
light = light_value * 0.062271;
if (light > 40)
{
FastLED.setBrightness(light);
}
else
{
FastLED.setBrightness(BRIGHTNESS);
}
// auto brightness
#ifdef LIGHTSENSORPIN
int light_value = analogRead(LIGHTSENSORPIN);
light = light_value * 0.062271;
if (light > 40)
{
FastLED.setBrightness(light);
}
else
{
FastLED.setBrightness(BRIGHTNESS);
}
#endif
decoder.decodeFrame();
}
// else
// {
// if (!wifiManager.startConfigPortal("OnDemandAP")) {
// Serial.println("failed to connect and hit timeout");
// delay(3000);
// connect = false;
// //reset and try again, or maybe put it to deep sleep
// }
// //if you get here you have connected to the WiFi
// Serial.println("connected...yeey :)");
// if (WiFi.status() == WL_DISCONNECTED)
// {
// display_scrollText(String("Connect to: " + wifiManager.getConfigPortalSSID()));
// delay(1000);
// }
// else
// {
// if (serverRunning) {
// serverRunning = true;
// setupServer();
// }
// display_scrollText(String("Browse to: " + WiFi.localIP()));
// delay(1000);
// }
// }
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment