-
Notifications
You must be signed in to change notification settings - Fork 348
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added WS2812FXT class for effect transitions, and other minor bug fix…
…es. See the change log. (#291)
- Loading branch information
1 parent
6f5783d
commit d3047cc
Showing
12 changed files
with
651 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
This sketch is a modification of the ws2812fx_dma sketch, which uses | ||
Paul Stoffregen's WS2812Serial library (instead of Michael Miller's | ||
NeoPixelBus library) to enable the Teensy microcontroller's DMA to | ||
drive the LEDs. | ||
Note the WS2812Serial lib isn't installable from the Teensyduino IDE's | ||
Manage Libraries menu, but instead must be installed using the | ||
Sketch -> Include Library -> Add .ZIP Library after downloading | ||
WS2812Serial from Paul's GitHub page: | ||
https://github.com/PaulStoffregen/WS2812Serial | ||
Keith Lord - 2021 | ||
LICENSE | ||
The MIT License (MIT) | ||
Copyright (c) 2021 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 | ||
2021-08-20 initial version | ||
*/ | ||
|
||
#include <WS2812FX.h> | ||
#include <WS2812Serial.h> | ||
|
||
// Usable pins: | ||
// Teensy LC: 1, 4, 5, 24 | ||
// Teensy 3.2: 1, 5, 8, 10, 31 (overclock to 120 MHz for pin 8) | ||
// Teensy 3.5: 1, 5, 8, 10, 26, 32, 33, 48 | ||
// Teensy 3.6: 1, 5, 8, 10, 26, 32, 33 | ||
// Teensy 4.0: 1, 8, 14, 17, 20, 24, 29, 39 | ||
// Teensy 4.1: 1, 8, 14, 17, 20, 24, 29, 35, 47, 53 | ||
#define LED_PIN 1 // digital pin used to drive the LED strip | ||
#define LED_COUNT 144 // number of LEDs on the strip | ||
|
||
// allocate a display buffer for WS2812Serial | ||
DMAMEM byte displayMemory[LED_COUNT * 12]; // 12 bytes per RGB LED or 16 bytes per RGBW LED | ||
|
||
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); | ||
|
||
WS2812Serial *ws2812serialRef; | ||
|
||
void setup() { | ||
Serial.begin(115200); | ||
|
||
ws2812fx.init(); | ||
ws2812fx.setBrightness(32); | ||
|
||
const uint32_t colors[] = {GREEN, BLACK, BLACK}; | ||
ws2812fx.setSegment(0, 0, LED_COUNT-1, FX_MODE_LARSON_SCANNER, colors, 5000, NO_OPTIONS); | ||
|
||
ws2812fx.setCustomShow(myCustomShow); // set the custom show function | ||
ws2812fx.start(); | ||
|
||
// Instantiate and init the WS2812Serial instance last, so the LED_PIN pin is configured properly. | ||
// For the WS2812Serial instance always use WS2812_BGR, since it's sense of color byte order seems backwards. | ||
ws2812serialRef = new WS2812Serial(LED_COUNT, displayMemory, ws2812fx.getPixels(), LED_PIN, WS2812_BGR); | ||
ws2812serialRef->begin(); | ||
} | ||
|
||
void loop() { | ||
ws2812fx.service(); | ||
} | ||
|
||
void myCustomShow(void) { | ||
ws2812serialRef->show(); // run the WS2812Serial show() function | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
/* | ||
A demo of effect transitions. | ||
A new class WS2812FXT (note the 'T' at the end) provides the ability to | ||
create effect transitions. Note, WS2812FXT essentially creates THREE | ||
WS2812FX instances to do it's work, so uses considerably more memory | ||
than the normal WS2812FX class. | ||
WS2812FXT creates three WS2812FX objects, two virtual LED strips (v1 and v2) | ||
and one physical strip (p1). You setup the two virtual strips using the normal | ||
WS2812FX API, where each virtual strip can have its own brightness, effect, | ||
speed, segments, etc. The physical strip is used to drive the LLEDs. Behind | ||
the scenes WS2812FXT takes care of blending the two virtual strips together | ||
to create the transition from v1 to v2 on the physical strip. | ||
To transition from the v1 effect to the v2 effect, call the startTransition() | ||
function passing in the duration of the transition (in ms), and optionally | ||
the transition direction (i.e direction == true produces a transition from | ||
v1 to v2, while direction == false produces a transition from v2 to v1). | ||
LICENSE | ||
The MIT License (MIT) | ||
Copyright (c) 2021 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 | ||
2021-08-20 initial version | ||
*/ | ||
|
||
#include <WS2812FX.h> | ||
|
||
#define LED_PIN 4 | ||
#define LED_COUNT 144 | ||
|
||
WS2812FXT ws2812fxt = WS2812FXT(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800); | ||
|
||
void setup() { | ||
|
||
ws2812fxt.init(); | ||
|
||
// setup the effects on the two virtual strips | ||
// note v1 and v2 are pointers, so you must use pointer syntax | ||
// (i.e. use ws2812fxt.v1->setMode(...), not ws2812fxt.v1.setMode(...)) | ||
ws2812fxt.v1->setBrightness(32); | ||
ws2812fxt.v1->setSegment(0, 0, LED_COUNT-1, FX_MODE_RAINBOW_CYCLE, BLACK, 5000); | ||
|
||
ws2812fxt.v2->setBrightness(128); | ||
ws2812fxt.v2->setSegment(0, 0, LED_COUNT-1, FX_MODE_LARSON_SCANNER, BLUE, 3000); | ||
|
||
ws2812fxt.start(); | ||
} | ||
|
||
void loop() { | ||
ws2812fxt.service(); | ||
|
||
// every ten seconds transition from v1 to v2 then back to v1 | ||
static bool direction = true; | ||
static unsigned long timer = 10000; | ||
unsigned long now = millis(); | ||
|
||
if(now > timer) { | ||
ws2812fxt.startTransition(5000, direction); // transition duration = 5 seconds | ||
direction = !direction; // change the transition direction | ||
timer = now + 10000; // transition every ten seconds | ||
} | ||
} |
Oops, something went wrong.