Skip to content

Commit

Permalink
Added built-in rain effect and bug fixes. See change log. (#301)
Browse files Browse the repository at this point in the history
* Minor updates

* Fixed bug that prevented the last LED from updaing on some effects.

* added rain effect and updated library.json file
  • Loading branch information
moose4lord authored Nov 19, 2021
1 parent d3047cc commit a02c0d7
Show file tree
Hide file tree
Showing 20 changed files with 162 additions and 303 deletions.
15 changes: 5 additions & 10 deletions examples/esp8266_webinterface/esp8266_webinterface.ino
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,6 @@ extern const char main_js[];
#define WIFI_TIMEOUT 30000 // checks WiFi every ...ms. Reset after this time, if WiFi cannot reconnect.
#define HTTP_PORT 80

#define DEFAULT_COLOR 0xFF5900
#define DEFAULT_BRIGHTNESS 128
#define DEFAULT_SPEED 1000
#define DEFAULT_MODE FX_MODE_STATIC

unsigned long auto_last_change = 0;
unsigned long last_wifi_check_time = 0;
String modes = "";
Expand All @@ -100,10 +95,10 @@ void setup(){

Serial.println("WS2812FX setup");
ws2812fx.init();
ws2812fx.setMode(DEFAULT_MODE);
ws2812fx.setColor(DEFAULT_COLOR);
ws2812fx.setSpeed(DEFAULT_SPEED);
ws2812fx.setBrightness(DEFAULT_BRIGHTNESS);
ws2812fx.setMode(FX_MODE_STATIC);
ws2812fx.setColor(0xFF5900);
ws2812fx.setSpeed(1000);
ws2812fx.setBrightness(128);
ws2812fx.start();

Serial.println("Wifi setup");
Expand Down Expand Up @@ -231,7 +226,7 @@ void srv_handle_set() {
for (uint8_t i=0; i < server.args(); i++){
if(server.argName(i) == "c") {
uint32_t tmp = (uint32_t) strtol(server.arg(i).c_str(), NULL, 10);
if(tmp >= 0x000000 && tmp <= 0xFFFFFF) {
if(tmp <= 0xFFFFFF) {
ws2812fx.setColor(tmp);
}
}
Expand Down
71 changes: 0 additions & 71 deletions examples/ws2812fx_esp32/ESP32_RMT_Driver.h

This file was deleted.

93 changes: 0 additions & 93 deletions examples/ws2812fx_esp32/ws2812fx_esp32.ino

This file was deleted.

2 changes: 1 addition & 1 deletion examples/ws2812fx_limit_current/ws2812fx_limit_current.ino
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ void recvChar(void) {
#define MAX_CURRENT 500 // maximum allowed current draw for the entire strip (mA)
#define QUIESCENT_CURRENT 56 // current draw for the entire strip with all LEDs off (mA)
#define INCREMENTAL_CURRENT 40 // increase in current for each intensity step per RGB color (uA)
#define MAX_INTENSITY_SUM ((MAX_CURRENT - QUIESCENT_CURRENT) * 1000) / INCREMENTAL_CURRENT
#define MAX_INTENSITY_SUM ((MAX_CURRENT - QUIESCENT_CURRENT) * (uint32_t)1000) / INCREMENTAL_CURRENT
void myCustomShow(void) {
static uint32_t lastSum = 0;
uint32_t intensitySum = ws2812fx.intensitySum(); // get intensity sum for all LEDs
Expand Down
2 changes: 1 addition & 1 deletion examples/ws2812fx_matrix/ws2812fx_matrix.ino
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define PSTR // Make Arduino Due happy
#endif

#define PIN D5
#define PIN 4

// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
Expand Down
6 changes: 3 additions & 3 deletions examples/ws2812fx_msgeq7/ws2812fx_msgeq7.ino
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,16 @@
#include <WS2812FX.h>

#define LED_COUNT 140
#define LED_PIN D1
#define LED_PIN 4

// include and config the VUMeter custom effect
#define NUM_BANDS 7
#define USE_RANDOM_DATA false
#include "custom/VUMeter.h"

// MSGEQ7 pin assignments
#define STROBE D5
#define RESET D6
#define STROBE 5
#define RESET 6
#define OUT A0
#define MSGEQ7_DELAY 50

Expand Down
2 changes: 1 addition & 1 deletion examples/ws2812fx_overlay/ws2812fx_overlay.ino
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void myCustomShow(void) {

// blend the pixel data from the virtual strips and save it
// to the physical strip
for (int i=0; i < ws2812fx_p.getNumBytes(); i++) {
for (uint16_t i=0; i < ws2812fx_p.getNumBytes(); i++) {
pixels_p[i] = (pixels_v1[i] / 2) + (pixels_v2[i] / 2);
}

Expand Down
16 changes: 8 additions & 8 deletions examples/ws2812fx_patterns_web/ws2812fx_patterns_web.ino
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ uint16_t numLeds = 30; // default number of LEDs on the strip

#define MAX_NUM_PATTERNS 8
// duration, brightness, numSegments, [ { first, last, speed, mode, options, colors[] } ]
#define DEFAULT_PATTERN {30, 64, 1, { {0, numLeds-1, numLeds*20, FX_MODE_STATIC, NO_OPTIONS, {RED, BLACK, BLACK}} }}
#define DEFAULT_PATTERN {30, 64, 1, { {0, (uint16_t)(numLeds-1), (uint16_t)(numLeds*20), FX_MODE_STATIC, NO_OPTIONS, {RED, BLACK, BLACK}} }}

typedef struct Pattern { // 208 bytes/pattern
int duration;
Expand Down Expand Up @@ -143,7 +143,7 @@ void loop() {

// if it's time to change pattern, do it now
unsigned long now = millis();
if (lastTime == 0 || (now - lastTime > patterns[currentPattern].duration * 1000)) {
if (lastTime == 0 || (now - lastTime > patterns[currentPattern].duration * 1000ul)) {
ws2812fx.clear();
ws2812fx.resetSegments();

Expand Down Expand Up @@ -176,7 +176,7 @@ void configServer() {
String auxFunc = server.arg("auxFunc");
if (auxFunc.length() > 0) {
int auxFuncIndex = auxFunc.toInt();
if (auxFuncIndex >= 0 && auxFuncIndex < sizeof(customAuxFunc) / sizeof(customAuxFunc[0])) {
if (auxFuncIndex >= 0 && (size_t)auxFuncIndex < sizeof(customAuxFunc) / sizeof(customAuxFunc[0])) {
customAuxFunc[auxFuncIndex]();
}
}
Expand Down Expand Up @@ -371,7 +371,7 @@ bool json2patterns(String &json) {
JsonArray patternsJson = deviceJson["patterns"];
if (patternsJson.size() > 0 ) {
numPatterns = 0;
for (int i = 0; i < patternsJson.size(); i++) {
for (size_t i = 0; i < patternsJson.size(); i++) {
JsonObject patt = patternsJson[i];
// bool isEnabled = patt["isEnabled"];
// if (! isEnabled) continue; // disabled patterns are not stored
Expand All @@ -383,7 +383,7 @@ bool json2patterns(String &json) {
patterns[numPatterns].duration = patt["duration"];

patterns[numPatterns].numSegments = segmentsJson.size();
for (int j = 0; j < segmentsJson.size(); j++) {
for (size_t j = 0; j < segmentsJson.size(); j++) {
JsonObject seg = segmentsJson[j];
//seg.printTo(Serial);Serial.println();

Expand Down Expand Up @@ -420,9 +420,9 @@ bool json2patterns(String &json) {

JsonArray colors = seg["colors"]; // the web interface sends three color values
// convert colors from strings ('#ffffff') to uint32_t
patterns[numPatterns].segments[j].colors[0] = strtoul(colors[0].as<char*>() + 1, 0, 16);
patterns[numPatterns].segments[j].colors[1] = strtoul(colors[1].as<char*>() + 1, 0, 16);
patterns[numPatterns].segments[j].colors[2] = strtoul(colors[2].as<char*>() + 1, 0, 16);
patterns[numPatterns].segments[j].colors[0] = strtoul(colors[0].as<const char*>() + 1, 0, 16);
patterns[numPatterns].segments[j].colors[1] = strtoul(colors[1].as<const char*>() + 1, 0, 16);
patterns[numPatterns].segments[j].colors[2] = strtoul(colors[2].as<const char*>() + 1, 0, 16);
}
numPatterns++;
if (numPatterns >= MAX_NUM_PATTERNS) break;
Expand Down
4 changes: 2 additions & 2 deletions examples/ws2812fx_segments_web/ws2812fx_segments_web.ino
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
AsyncWebServer server(80);

typedef struct Preset {
struct Preset {
int pin = LED_PIN;
int numPixels = LED_COUNT;
int brightness = 64;
Expand Down Expand Up @@ -203,7 +203,7 @@ void initWebAPI() {

JsonArray segments = jsonObj["segments"];
preset.numSegments = segments.size();
for (int i = 0; i < segments.size(); i++) {
for (size_t i = 0; i < segments.size(); i++) {
JsonObject seg = segments[i];

preset.segments[i].start = seg["start"];
Expand Down
14 changes: 7 additions & 7 deletions examples/ws2812fx_soundfx/ws2812fx_soundfx.ino
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
FEATURES
* example of running an LED animation with sound effects.
* The WAV audio files are stored in the ESP's SPIFFS
* The WAV audio files are stored in the ESP8266's LittleFS
* filesystem and need to be uploaded to the ESP before
* uploading the sketch, as described here:
* https://arduino-esp8266.readthedocs.io/en/stable/filesystem.html#file-system-object-spiffs
* https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html#uploading-files-to-file-system
*
* We're using the fantastic ESP8266Audio library available here:
* https://github.com/earlephilhower/ESP8266Audio.
Expand Down Expand Up @@ -67,7 +67,7 @@
*/

#include <WS2812FX.h>
#include "AudioFileSourceSPIFFS.h"
#include "AudioFileSourceLittleFS.h"
#include "AudioGeneratorWAV.h"
#include "AudioOutputI2S.h"

Expand All @@ -77,15 +77,15 @@
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);

AudioGeneratorWAV *wav = NULL;
AudioFileSourceSPIFFS *file = NULL;
AudioFileSourceLittleFS *file = NULL;
AudioOutputI2S *out = NULL;

char* soundfx = "/pew.wav";
const char* soundfx = "/pew.wav";

void setup() {
Serial.begin(115200);

SPIFFS.begin(); // init SPIFFS file system where the audio samples are stored
LittleFS.begin(); // init LittleFS file system where the audio samples are stored

ws2812fx.init();
ws2812fx.setBrightness(255);
Expand Down Expand Up @@ -115,7 +115,7 @@ void playSound() {
if(out != NULL) delete out;
if(wav != NULL) delete wav;

file = new AudioFileSourceSPIFFS(soundfx);
file = new AudioFileSourceLittleFS(soundfx);
out = new AudioOutputI2S();
wav = new AudioGeneratorWAV();

Expand Down
Loading

0 comments on commit a02c0d7

Please sign in to comment.