Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
144 changes: 133 additions & 11 deletions LEDLAMP_FASTLEDs.ino
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
#include <WebSockets.h> //https://github.com/Links2004/arduinoWebSockets
#include <WebSocketsServer.h>

// OTA
#ifdef ENABLE_OTA
#include <WiFiUdp.h>
#include <ArduinoOTA.h>
#endif


// ***************************************************************************
// Instanciate HTTP(80) / WebSockets(81) Server
Expand Down Expand Up @@ -53,10 +59,15 @@ void configModeCallback (WiFiManager *myWiFiManager) {
DBG_OUTPUT_PORT.println(myWiFiManager->getConfigPortalSSID());
//entered config mode, make led toggle faster
ticker.attach(0.2, tick);
}



// Show USER that module can't connect to stored WiFi
uint16_t i;
for (i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(100, 0, 0);
}
FastLED.show();

}

// ***************************************************************************
// Include: Webserver
Expand All @@ -73,10 +84,6 @@ void configModeCallback (WiFiManager *myWiFiManager) {
// ***************************************************************************
#include "colormodes.h"





// ***************************************************************************
// MAIN
// ***************************************************************************
Expand All @@ -94,6 +101,8 @@ void setup() {
// start ticker with 0.5 because we start in AP mode and try to connect
ticker.attach(0.6, tick);



// ***************************************************************************
// Setup: WiFiManager
// ***************************************************************************
Expand Down Expand Up @@ -127,6 +136,12 @@ void setup() {
// Setup: FASTLED
// ***************************************************************************
delay(3000); // 3 second delay for recovery

// limit my draw to 2.1A at 5v of power draw
FastLED.setMaxPowerInVoltsAndMilliamps(5,maxCurrent);

// maximum refresh rate
FastLED.setMaxRefreshRate(fastled_hz);

// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
Expand All @@ -135,14 +150,72 @@ void setup() {
// set master brightness control
FastLED.setBrightness(brightness);

// ***************************************************************************
// Configure OTA
// ***************************************************************************
#ifdef ENABLE_OTA
DBG_OUTPUT_PORT.println("Arduino OTA activated.");

// Port defaults to 8266
// ArduinoOTA.setPort(8266);

// Hostname defaults to esp8266-[ChipID]
ArduinoOTA.setHostname(HOSTNAME);

// No authentication by default
// ArduinoOTA.setPassword("admin");

// Password can be set with it's md5 value as well
// MD5(admin) = 21232f297a57a5a743894a0e4a801fc3
// ArduinoOTA.setPasswordHash("21232f297a57a5a743894a0e4a801fc3");

ArduinoOTA.onStart([]() {
DBG_OUTPUT_PORT.println("Arduino OTA: Start updating");
ticker.attach(0.1, tick); // Do blink faster to show running OTA update
});

ArduinoOTA.onEnd([]() {
DBG_OUTPUT_PORT.println("Arduino OTA: End");
ticker.detach();
//keep LED on
digitalWrite(BUILTIN_LED, LOW);
});
ArduinoOTA.onProgress([](unsigned int progress, unsigned int total) {
DBG_OUTPUT_PORT.printf("Arduino OTA Progress: %u%%\r", (progress / (total / 100)));
});

ArduinoOTA.onError([](ota_error_t error) {
DBG_OUTPUT_PORT.printf("Arduino OTA Error[%u]: ", error);
if (error == OTA_AUTH_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: Auth Failed");
else if (error == OTA_BEGIN_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: Begin Failed");
else if (error == OTA_CONNECT_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: Connect Failed");
else if (error == OTA_RECEIVE_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: Receive Failed");
else if (error == OTA_END_ERROR) DBG_OUTPUT_PORT.println("Arduino OTA: End Failed");
});

ArduinoOTA.begin();
DBG_OUTPUT_PORT.println("");
#endif


// ***************************************************************************
// Setup: MDNS responder
// ***************************************************************************
MDNS.begin(HOSTNAME);

DBG_OUTPUT_PORT.print("Open http://");
DBG_OUTPUT_PORT.print(WiFi.localIP());
DBG_OUTPUT_PORT.println("/ to get LED controller interface.");
DBG_OUTPUT_PORT.println("");
DBG_OUTPUT_PORT.print("File editor is available at http://");
DBG_OUTPUT_PORT.print(WiFi.localIP());
DBG_OUTPUT_PORT.println("/edit");
DBG_OUTPUT_PORT.println("");
DBG_OUTPUT_PORT.println("New users:");
DBG_OUTPUT_PORT.print("Open http://");
DBG_OUTPUT_PORT.print(HOSTNAME);
DBG_OUTPUT_PORT.println(".local/edit to see the file browser");
DBG_OUTPUT_PORT.print(WiFi.localIP());
DBG_OUTPUT_PORT.println("/upload to upload the webpages first.");



// ***************************************************************************
Expand Down Expand Up @@ -295,7 +368,35 @@ void setup() {
getStatusJSON();
});

server.on("/sinelon", []() {
server.on("/fire", []() {
exit_func = true;
mode = FIRE;
getArgs();
getStatusJSON();
});

server.on("/fworks", []() {
exit_func = true;
mode = FIREWORKS;
getArgs();
getStatusJSON();
});

server.on("/fwsingle", []() {
exit_func = true;
mode = FIREWORKS_SINGLE;
getArgs();
getStatusJSON();
});

server.on("/fwrainbow", []() {
exit_func = true;
mode = FIREWORKS_RAINBOW;
getArgs();
getStatusJSON();
});

server.on("/sinelon", []() {
exit_func = true;
mode = SINELON;
getArgs();
Expand Down Expand Up @@ -334,9 +435,13 @@ void setup() {
}

void loop() {
#ifdef ENABLE_OTA
ArduinoOTA.handle();
#endif

server.handleClient();
webSocket.loop();
// ArduinoOTA.handle();
// yield();

EVERY_N_MILLISECONDS(int(float(1000/FPS))) { gHue++; } // slowly cycle the "base color" through the rainbow
Expand Down Expand Up @@ -383,6 +488,23 @@ void loop() {
if (mode == SINELON) {
sinelon();
}

if (mode == FIRE) {
fire2012();
}

if (mode == FIREWORKS) {
fireworks();
}

if (mode == FIREWORKS_SINGLE) {
fw_single();
}

if (mode == FIREWORKS_RAINBOW) {
fw_rainbow();
}


if (mode == JUGGLE) {
juggle();
Expand Down
52 changes: 22 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
# Russell's FASTLEDs
I mixed the work of @toblum with the @FastLED (FastLED library 3.1.3 as of this writing), the colorjs colorpicker, color spectrums created via FastLED Palette Knife, and some additional strip animations (included in the Arduino Sketch above).
# doctormord's FASTLEDs - OBSOLETE!

Please check new repo at:

https://github.com/doctormord/Responsive_LED_Control



I mixed the work of [McLighting](https://github.com/toblum/McLighting) and [Russell](https://github.com/russp81/LEDLAMP_FASTLEDs) with [FastLED](https://github.com/FastLED/FastLED) (FastLED library 3.1.3 as of this writing), the colorjs colorpicker, color spectrums created via FastLED Palette Knife, and some additional strip animations (included in the Arduino Sketch above).

FastLED 3.1.3 library:
https://github.com/FastLED/FastLED

McLighting library:
https://github.com/toblum/McLighting

Russel's implementation:
https://github.com/russp81/LEDLAMP_FASTLEDs

jscolor Color Picker:
http://jscolor.com/

Expand All @@ -26,36 +36,18 @@ In short you will:
of the ESP followed by "/edit" (i.e. 192.168.1.20/edit). Then upload the files from the folder labeled "upload these" from this repo.
5. Once you have finished uploading, type in the IP of the ESP into your browser and you should be up and running!

Forked from Russel, i removed Adafruit Neopixel references and library calls.

My work was all on adding FastLED (and other tweaks / animations) into the McLighting sketch instead of using Adafruit NeoPixel.
Added/changed so far:

I am a self taught coder who learns by a few books, google, and looking at other's code,
and I just liked the things you can do in FastLED better, so I decided to tackle the
idea of integrating FastLED into the already awesome work of @toblum.
* new effect: Fire (from WS2812FX)
* new effect: Fireworks [single color, rainbow, random] (from McLightning, ported to used FastLED instead off Adafruit Neopixel)
* new settings for effects in webinterface *.htm
* integrated Arduino OTA

I have a limited grasp on the h/w and s/w relationships (do's and don't do's, etc).
I edited clockless_esp8266.h (in the FastLED platforms folder) and
kept getting flickering until I incremented the WAIT_TIME up to 18us.
(also I did "#define FASTLED_INTERRUPT_RETRY_COUNT 3" inside my sketch).

If I disabled interrupts altogether "#define FASTLED_ALLOW_INTERRUPTS 0", the strip would stop flickering but I would get
what I believe to be "watchdog resets" every 5 to 20 minutes depending on what animation was running, wifi traffic, etc...

For reference, I learned more about the interrupts issue from here: https://github.com/FastLED/FastLED/issues/306

If anyone can shed more light on this I am all ears! I'm not sure exactly what the implications are
for setting the WAIT_TIME = 18us?? Everything appears to function properly, and so far I have not seen
a reset in a few hours.

Also, I added a separate color picker from (http://jscolor.com/). My idea with this is to eventually create
spectrums using multiple color pickers via the web interface (instead of grinding out coding in the Arduino IDE)
and eventually animate them as well. When I am finished with this project, I (we) will hopefully be able to build those
spectrums, save them to the ESP8266 flash memory, and have a universal routine in the Arduino Sketch that can handle
the input / output of the spectrums to the strip (even running animations with them). I also might even try making a web interface
to create custom animations from, but that seems like a pretty decent challenge from what I can tell. (I am just now finding my way
around in html/css/js so I have A LOT of learning to do!)

I will say again, I'm a rookie who has tinkered around in a little of each major language with no formal education, so
if you see something that doesn't look right, it probably isn't! I am very open to suggestions / learning anything
anyone is willing to share.
~~I edited clockless_esp8266.h (in the FastLED platforms folder) and
kept getting flickering until I incremented the WAIT_TIME up to 18us.
(also I did "#define FASTLED_INTERRUPT_RETRY_COUNT 3" inside my sketch).~~

For reference, interrupts issue: https://github.com/FastLED/FastLED/issues/306
Loading