Permalink
Browse files

Expanded custom effects and minor bug fixes (#108)

  • Loading branch information...
moose4lord committed Jul 21, 2018
1 parent bcdc50e commit 12cd48cedb8affe0ff58b50f50d2a11b1780ebbe
View
@@ -1,4 +1,5 @@
.vscode/c_cpp_properties.json
.vscode/arduino.json
.vscode/settings.json
.DS_Store
*.development
@@ -4,14 +4,6 @@
#define LED_COUNT 30
#define LED_PIN 5
// ESP boards generate a "section type conflict with __c" error when
// putting non-global strings in PROGMEM. i.e. can't use F() for local strings.
#if defined(__AVR__) // Arduino
#define STRING(x) F(x)
#else // ESP
#define STRING(x) x
#endif
// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
@@ -57,65 +49,65 @@ void loop() {
* Checks received command and calls corresponding functions.
*/
void process_command() {
if(cmd == STRING("b+")) {
if(cmd == F("b+")) {
ws2812fx.increaseBrightness(25);
Serial.print(STRING("Increased brightness by 25 to: "));
Serial.print(F("Increased brightness by 25 to: "));
Serial.println(ws2812fx.getBrightness());
}
if(cmd == STRING("b-")) {
if(cmd == F("b-")) {
ws2812fx.decreaseBrightness(25);
Serial.print(STRING("Decreased brightness by 25 to: "));
Serial.print(F("Decreased brightness by 25 to: "));
Serial.println(ws2812fx.getBrightness());
}
if(cmd.startsWith(STRING("b "))) {
if(cmd.startsWith(F("b "))) {
uint8_t b = (uint8_t) cmd.substring(2, cmd.length()).toInt();
ws2812fx.setBrightness(b);
Serial.print(STRING("Set brightness to: "));
Serial.print(F("Set brightness to: "));
Serial.println(ws2812fx.getBrightness());
}
if(cmd == STRING("s+")) {
if(cmd == F("s+")) {
// ws2812fx.increaseSpeed(10);
ws2812fx.setSpeed(ws2812fx.getSpeed() * 1.2);
Serial.print(STRING("Increased speed by 20% to: "));
Serial.print(F("Increased speed by 20% to: "));
Serial.println(ws2812fx.getSpeed());
}
if(cmd == STRING("s-")) {
if(cmd == F("s-")) {
// ws2812fx.decreaseSpeed(10);
ws2812fx.setSpeed(ws2812fx.getSpeed() * 0.8);
Serial.print(STRING("Decreased speed by 20% to: "));
Serial.print(F("Decreased speed by 20% to: "));
Serial.println(ws2812fx.getSpeed());
}
if(cmd.startsWith(STRING("s "))) {
if(cmd.startsWith(F("s "))) {
uint16_t s = (uint16_t) cmd.substring(2, cmd.length()).toInt();
ws2812fx.setSpeed(s);
Serial.print(STRING("Set speed to: "));
Serial.print(F("Set speed to: "));
Serial.println(ws2812fx.getSpeed());
}
if(cmd.startsWith(STRING("m "))) {
if(cmd.startsWith(F("m "))) {
uint8_t m = (uint8_t) cmd.substring(2, cmd.length()).toInt();
ws2812fx.setMode(m);
Serial.print(STRING("Set mode to: "));
Serial.print(F("Set mode to: "));
Serial.print(ws2812fx.getMode());
Serial.print(" - ");
Serial.println(ws2812fx.getModeName(ws2812fx.getMode()));
}
if(cmd.startsWith(STRING("c "))) {
if(cmd.startsWith(F("c "))) {
uint32_t c = (uint32_t) strtol(&cmd.substring(2, cmd.length())[0], NULL, 16);
ws2812fx.setColor(c);
Serial.print(STRING("Set color to: "));
Serial.print(STRING("0x"));
if(ws2812fx.getColor() < 0x100000) { Serial.print(STRING("0")); }
if(ws2812fx.getColor() < 0x010000) { Serial.print(STRING("0")); }
if(ws2812fx.getColor() < 0x001000) { Serial.print(STRING("0")); }
if(ws2812fx.getColor() < 0x000100) { Serial.print(STRING("0")); }
if(ws2812fx.getColor() < 0x000010) { Serial.print(STRING("0")); }
Serial.print(F("Set color to: "));
Serial.print(F("0x"));
if(ws2812fx.getColor() < 0x100000) { Serial.print(F("0")); }
if(ws2812fx.getColor() < 0x010000) { Serial.print(F("0")); }
if(ws2812fx.getColor() < 0x001000) { Serial.print(F("0")); }
if(ws2812fx.getColor() < 0x000100) { Serial.print(F("0")); }
if(ws2812fx.getColor() < 0x000010) { Serial.print(F("0")); }
Serial.println(ws2812fx.getColor(), HEX);
}
@@ -127,23 +119,23 @@ void process_command() {
* Prints a usage menu.
*/
void printUsage() {
Serial.println(STRING("Usage:"));
Serial.println(F("Usage:"));
Serial.println();
Serial.println(STRING("m <n> \t : select mode <n>"));
Serial.println(F("m <n> \t : select mode <n>"));
Serial.println();
Serial.println(STRING("b+ \t : increase brightness"));
Serial.println(STRING("b- \t : decrease brightness"));
Serial.println(STRING("b <n> \t : set brightness to <n>"));
Serial.println(F("b+ \t : increase brightness"));
Serial.println(F("b- \t : decrease brightness"));
Serial.println(F("b <n> \t : set brightness to <n>"));
Serial.println();
Serial.println(STRING("s+ \t : increase speed"));
Serial.println(STRING("s- \t : decrease speed"));
Serial.println(STRING("s <n> \t : set speed to <n>"));
Serial.println(F("s+ \t : increase speed"));
Serial.println(F("s- \t : decrease speed"));
Serial.println(F("s <n> \t : set speed to <n>"));
Serial.println();
Serial.println(STRING("c 0x007BFF \t : set color to 0x007BFF"));
Serial.println(F("c 0x007BFF \t : set color to 0x007BFF"));
Serial.println();
Serial.println();
Serial.println(STRING("Have a nice day."));
Serial.println(STRING("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"));
Serial.println(F("Have a nice day."));
Serial.println(F("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"));
Serial.println();
}
@@ -152,11 +144,11 @@ void printUsage() {
* Prints all available WS2812FX blinken modes.
*/
void printModes() {
Serial.println(STRING("Supporting the following modes: "));
Serial.println(F("Supporting the following modes: "));
Serial.println();
for(int i=0; i < ws2812fx.getModeCount(); i++) {
Serial.print(i);
Serial.print(STRING("\t"));
Serial.print(F("\t"));
Serial.println(ws2812fx.getModeName(i));
}
Serial.println();
@@ -34,7 +34,7 @@
#include <WS2812FX.h>
#define LED_COUNT 30
#define LED_PIN D1
#define LED_PIN 5
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
@@ -0,0 +1,65 @@
/*
Demo sketch for creating multiple custom effects.
Keith Lord - 2018
LICENSE
The MIT License (MIT)
Copyright (c) 2018 Keith Lord
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sub-license, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
CHANGELOG
2018-07-19 initial version
*/
#include <WS2812FX.h>
// include the custom effects
#include "custom/DualLarson.h"
#include "custom/RandomChase.h"
#define LED_COUNT 30
#define LED_PIN 5
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(115200);
ws2812fx.init();
ws2812fx.setBrightness(255);
// setup the custom effects
uint8_t randomChaseMode = ws2812fx.setCustomMode(F("Random Chase"), randomChase);
uint8_t dualLarsonMode = ws2812fx.setCustomMode(F("Dual Larson"), dualLarson);
uint32_t colors[] = {RED, BLUE, WHITE};
ws2812fx.setSegment(0, 0, LED_COUNT/2 - 1, randomChaseMode, BLUE, 50, NO_OPTIONS);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT - 1, dualLarsonMode, colors, 2000, FADE_SLOW);
ws2812fx.start();
}
void loop() {
ws2812fx.service();
}
@@ -1,5 +1,31 @@
WS2182FX Change Log
v1.0.7 changes 7/19/2018
------------------------
1) Moved the _name array variable out of the WS2812FX class and made
it a global variable. This fixes the problem where putting local
variables in PROGMEM (with the F() macro) caused "section type conflict
with __c" compiler error for ESP implementations.
See this issue: https://github.com/kitesurfer1404/WS2812FX/issues/83
Also, the examples/serial_control sketch was refactored to remove the ugly
code hack used to workaround this problem in the past.
As a bonus, making _name a global variable is more memory efficient and
reduces the Arduino flash memory footprint by 1600 bytes.
2) Expanded the custom effect feature to allow for up to four custom
effects. See the examples/ws2812fx_custom_effect2 sketch for a demo
of using more then one custom effect in a sketch.
3) added a src/custom folder to contain user written custom effects. To
maintain Arduino compatibility, with its limited flash memory, it's not
practical to just incorporating more and more effects into the library.
Creating a folder for custom effects, that users can pick and choose
from, is a first step toward partitioning the mode/effect code base.
v1.0.6 changes 6/12/2018
------------------------
View
@@ -126,3 +126,8 @@ FX_MODE_BICOLOR_CHASE KEYWORD2
FX_MODE_TRICOLOR_CHASE KEYWORD2
FX_MODE_ICU KEYWORD2
FX_MODE_CUSTOM KEYWORD2
FX_MODE_CUSTOM_0 KEYWORD2
FX_MODE_CUSTOM_1 KEYWORD2
FX_MODE_CUSTOM_2 KEYWORD2
FX_MODE_CUSTOM_3 KEYWORD2
View
@@ -6,7 +6,7 @@
"name": "Harm Aldick",
"url": "https://github.com/kitesurfer1404/WS2812FX"
},
"version": "1.0.6",
"version": "1.0.7",
"downloadUrl": "https://github.com/kitesurfer1404/WS2812FX/archive/master.zip",
"export": {
"include": "WS2812FX-master"
View
@@ -1,5 +1,5 @@
name=WS2812FX
version=1.0.6
version=1.0.7
author=Harm Aldick
maintainer=Harm Aldick
sentence=WS2812 FX Library for Arduino and ESP8266.
View
@@ -264,7 +264,7 @@ WS2812FX::Segment* WS2812FX::getSegments(void) {
const __FlashStringHelper* WS2812FX::getModeName(uint8_t m) {
if(m < MODE_COUNT) {
return _name[m];
return _names[m];
} else {
return F("");
}
@@ -1385,21 +1385,40 @@ uint16_t WS2812FX::mode_icu(void) {
}
/*
* Custom mode
* Custom modes
*/
uint16_t WS2812FX::mode_custom() {
if(customMode == NULL) {
return 1000; // if custom mode not set, do nothing
} else {
return customMode();
}
uint16_t WS2812FX::mode_custom_0() {
return customMode0();
}
uint16_t WS2812FX::mode_custom_1() {
return customMode1();
}
uint16_t WS2812FX::mode_custom_2() {
return customMode2();
}
uint16_t WS2812FX::mode_custom_3() {
return customMode3();
}
/*
* Custom mode helper
* Custom mode helpers
*/
void WS2812FX::setCustomMode(uint16_t (*p)()) {
customMode = p;
customMode0 = p;
}
uint8_t WS2812FX::setCustomMode(const __FlashStringHelper* name, uint16_t (*p)()) {
if(_custom_mode_index < MODE_COUNT) {
_names[_custom_mode_index] = name; // store the custom mode name
if(_custom_mode_index == FX_MODE_CUSTOM_0) customMode0 = p; // store the custom mode
if(_custom_mode_index == FX_MODE_CUSTOM_1) customMode1 = p;
if(_custom_mode_index == FX_MODE_CUSTOM_2) customMode2 = p;
if(_custom_mode_index == FX_MODE_CUSTOM_3) customMode3 = p;
_custom_mode_index++;
return (_custom_mode_index - 1);
}
return 0;
}
/*
Oops, something went wrong.

0 comments on commit 12cd48c

Please sign in to comment.