Skip to content

Commit 24d0df0

Browse files
authored
0.2 beta (#17)
* fix: code organization and simplification * feat: layer effects * wip: linked activations * wip: remove superfluous helper methods from pattern * wip: linked activations and deactivations * wip: bind color to periods with one method call * docs * update readme * gitignore * ignore dirs * readme updates * Delete .gitignore * Delete misc.xml * Delete modules.xml * Delete quickPatterns.iml * Delete vcs.xml * Delete settings.json
1 parent d6809c8 commit 24d0df0

47 files changed

Lines changed: 1557 additions & 978 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
/.idea
2+
/.vscode

README.md

Lines changed: 172 additions & 64 deletions
Large diffs are not rendered by default.

examples/bulb_lights/bulb_lights.ino

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ SOFTWARE.
3232
#include <quickPatterns.h>
3333

3434
#define CHIPSET WS2811
35-
#define DATA_PIN 8
35+
#define DATA_PIN 2
3636
#define NUM_LEDS 100
37-
#define BRIGHTNESS 32
37+
#define BRIGHTNESS 64
3838
#define COLOR_ORDER RGB //GRB for WS2812, RGB for WS2811
3939
#define TICKLENGTH 25
4040

@@ -47,6 +47,7 @@ void setup() {
4747
delay(3000); // Recovery delay
4848

4949
randomSeed(analogRead(1));
50+
// random16_add_entropy(analogRead(0));
5051

5152
// ~ Configure FastLED
5253

@@ -64,7 +65,7 @@ void setup() {
6465
quickPatterns.setTickMillis(TICKLENGTH);
6566

6667
// ~
67-
68+
6869
quickPatterns.addPattern(new qpPaletteDissolve(5))
6970
.usePalette(ForestColors_p);
7071

@@ -74,17 +75,16 @@ void setup() {
7475
.stayActiveForNTicks(80, 140);
7576
quickPatterns.sameLayer().setLayerBrush(COMBINE).continuallyFadeLayerBy(30);
7677

77-
7878
// ~
7979

8080
quickPatterns.newScene().addPattern(new qpPaletteWave(5))
8181
.usePalette(CRGBPalette16(CRGB::Yellow, CRGB::Orange, CRGB::Goldenrod, CRGB::Red));
8282

8383
quickPatterns.sameScene().addPattern(new qpSparkles(6))
84-
.chooseColorFromPalette(CRGBPalette16(CRGB::Red, CRGB(120, 0, 255)), SEQUENTIAL);
84+
.chooseColorFromPalette(CRGBPalette16(CRGB::Red, CRGB(120, 0, 255)), SEQUENTIAL)
85+
.changeColorEveryNTicks(2);
8586
quickPatterns.sameLayer().continuallyFadeLayerBy(20);
8687

87-
8888
// ~
8989

9090
quickPatterns.newScene().addPattern(new qpPaletteWave(5))
@@ -118,9 +118,7 @@ void setup() {
118118
void loop()
119119
{
120120

121-
// Refresh lights only when new frame data available, prevents issues with data timing on fast processors
122-
if(quickPatterns.draw())
123-
FastLED.show();
121+
quickPatterns.show();
124122

125123
EVERY_N_SECONDS(30) {
126124
quickPatterns.nextScene();
Lines changed: 266 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,266 @@
1+
/*****************************************************
2+
3+
quickPatterns demo reel - patterns to demonstrate some of the options available in the quickPatterns library
4+
https://github.com/brimshot/quickPatterns
5+
6+
MIT License
7+
8+
Copyright (c) 2021 Chris Brim
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a copy
11+
of this software and associated documentation files (the "Software"), to deal
12+
in the Software without restriction, including without limitation the rights
13+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
14+
copies of the Software, and to permit persons to whom the Software is
15+
furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included in all
18+
copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
23+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
26+
SOFTWARE.
27+
*****************************************************/
28+
29+
#ifdef CORE_TEENSY
30+
#define FASTLED_ALLOW_INTERRUPTS 0
31+
#endif
32+
33+
#include <quickPatterns.h>
34+
35+
//////////////////////////////////
36+
// HARDWARE CONSTANTS
37+
//////////////////////////////////
38+
39+
#define CHIPSET WS2812B
40+
#define DATA_PIN 2
41+
#define NUM_LEDS 150
42+
#define BRIGHTNESS 64
43+
#define COLOR_ORDER GRB //GRB for WS2812, RGB for WS2811
44+
45+
46+
//////////////////////////////////
47+
// CUSTOM PATTERNS FOR THIS SKETCH
48+
//
49+
// For information on writing custom patterns for use with quickPatterns see: https://github.com/brimshot/quickPatterns
50+
//
51+
//////////////////////////////////
52+
53+
// A juggle effect that slowly increases speed over time
54+
class increasingJuggle : public qpPattern {
55+
56+
private:
57+
const int MAX_SPEED = 2;
58+
const int FRAMES_TO_SHOW_AT_MAX_SPEED = 200;
59+
60+
int _startingSpeed;
61+
int speed;
62+
int velocity = 0;
63+
int framesRenderedAtMaxSpeed = 0;
64+
65+
void reset()
66+
{
67+
speed = _startingSpeed;
68+
velocity = framesRenderedAtMaxSpeed = 0;
69+
}
70+
71+
public:
72+
73+
increasingJuggle(int startingSpeed)
74+
{
75+
_startingSpeed = speed = startingSpeed;
76+
}
77+
78+
void draw() {
79+
80+
// Speed limiter
81+
if(this->frames % speed)
82+
return;
83+
84+
// Do juggle
85+
for( int i = 0; i < 8; i++)
86+
_targetLeds[beatsin16(i+7, 0, _numLeds - 1)] = _getColor();
87+
88+
// Increase velocity on each render
89+
velocity += 1;
90+
if(velocity%10 == 0)
91+
speed = max(--speed, MAX_SPEED);
92+
93+
// Stay at max speed for 200 frames then start over
94+
if(speed == MAX_SPEED) {
95+
if(++framesRenderedAtMaxSpeed == 200) {
96+
reset();
97+
}
98+
}
99+
100+
}
101+
102+
};
103+
104+
105+
// Sends segments of lights down the strip one by one and stacks them at the end
106+
class segmentStacker : public qpPattern {
107+
108+
private:
109+
const int FRAMES_TO_SHOW_WITH_FULL_STACK = 200;
110+
111+
int stackSize = 0;
112+
int segmentSize = 0;
113+
int segmentPos = 0;
114+
int framesWithFullStack = 0;
115+
116+
void reset() { segmentPos = stackSize = framesWithFullStack = 0; }
117+
118+
public:
119+
120+
segmentStacker(int segmentSize) : segmentSize(segmentSize) {}
121+
122+
void draw() {
123+
124+
// -. Quick note: we do NOT clear the leds here at the beginning of each loop since we are expecting other patterns on the same layer to do it for us
125+
126+
// Draw stack
127+
for(int i = (_numLeds-1); i > ((_numLeds-1) - stackSize); i--) {
128+
_targetLeds[i] = _getColor();
129+
}
130+
131+
// Pause or reset at end
132+
if(stackSize >= (_numLeds-1)) {
133+
if(framesWithFullStack < FRAMES_TO_SHOW_WITH_FULL_STACK) {
134+
framesWithFullStack++;
135+
return;
136+
}
137+
138+
reset();
139+
_countCycle();
140+
return;
141+
}
142+
143+
// Draw segment
144+
for(int i = segmentPos; i < (segmentPos + segmentSize); i++) {
145+
_targetLeds[i] = _getColor();
146+
}
147+
148+
// Advance segment pos for next frame
149+
segmentPos++;
150+
151+
// If we bumped into our stack, add it
152+
if((segmentPos + segmentSize) >= ((_numLeds-1) - stackSize)) {
153+
stackSize += segmentSize;
154+
segmentPos = 0;
155+
}
156+
157+
}
158+
159+
};
160+
161+
162+
//////////////////////////////////
163+
// MAIN SKETCH BEGINS HERE
164+
//////////////////////////////////
165+
166+
// Declare array of CRGB objects for use with FastLED
167+
CRGB leds[NUM_LEDS];
168+
169+
// declare quickPatterns controller and pass in main led array
170+
quickPatterns quickPatterns(leds, NUM_LEDS);
171+
172+
void setup() {
173+
174+
delay(3000); // Recovery delay
175+
176+
random16_add_entropy(analogRead(0));
177+
178+
// ~ Configure FastLED
179+
180+
FastLED.addLeds<CHIPSET, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
181+
.setCorrection(TypicalLEDStrip)
182+
.setDither(BRIGHTNESS < 255);
183+
184+
FastLED.setBrightness(BRIGHTNESS);
185+
FastLED.setMaxPowerInVoltsAndMilliamps(5, 450);
186+
187+
FastLED.clear();
188+
189+
190+
/////////// quickPatterns setup
191+
192+
// ----- Scene 1: Rainbow base layers with sparkling highlights that increase in speed as they shine
193+
194+
quickPatterns.newScene().addPattern(new qpPaletteGradient(2))
195+
.usePalette(RainbowColors_p)
196+
.drawEveryNTicks(2);
197+
198+
// Decoration layer: juggles that increase in speed then reset after a short time
199+
quickPatterns.sameScene().addPattern(new increasingJuggle(12))
200+
.singleColor(CRGB(128, 128, 128));
201+
quickPatterns.sameLayer().setLayerBrush(ADD).continuallyFadeLayerBy(20);
202+
203+
// ----- End Scene 1
204+
205+
// ----- Scene 2: Twinkling rainbow that is slowly revealed by stacking a visible window segment by segment
206+
207+
quickPatterns.newScene().addPattern(new qpPaletteTwinkle(12))
208+
.usePalette(RainbowColors_p);
209+
210+
quickPatterns.sameScene().addPattern(new qpFill())
211+
.singleColor(CRGB::Black);
212+
213+
quickPatterns.sameLayer().addPattern(new segmentStacker(10))
214+
.singleColor(CRGB::White);
215+
quickPatterns.sameLayer().setLayerBrush(MASK);
216+
217+
// ----- End Scene 2
218+
219+
220+
// ----- Scene 3: three overlapping layers at different speeds
221+
222+
quickPatterns.newScene().addPattern(new qpBouncingBars(9)) // blue bars, 9 pixels width
223+
.singleColor(CRGB::Blue);
224+
225+
quickPatterns.sameScene().addPattern(new qpBouncingBars(5)) // short red bars, 5 pixels
226+
.singleColor(CRGB::Red);
227+
quickPatterns.sameLayer().setLayerBrush(ADD); //when passing over underlying pixels, add their light together
228+
229+
quickPatterns.sameScene().addPattern(new qpBouncingBars(5)) // slow yellow bars, 5 pixels
230+
.singleColor(CRGB::Yellow)
231+
.drawEveryNTicks(3); //move at a slower speed
232+
quickPatterns.sameLayer().setLayerBrush(COMBINE);
233+
234+
// ----- End Scene 3
235+
236+
237+
// ----- Scene 4: Linked activations and deactivations
238+
239+
qpPattern &Sinelon = quickPatterns.newScene().addPattern(new qpSinelon(16))
240+
.chooseColorFromPalette(RainbowColors_p, SEQUENTIAL)
241+
.changeColorEveryNTicks(2);
242+
quickPatterns.sameLayer().continuallyFadeLayerBy(20);
243+
244+
qpPattern &WhiteLightning = quickPatterns.sameScene().addPattern(new qpLightning(12))
245+
.singleColor(CRGB::White)
246+
.activateWhenPatternPHasCompletedNCycles(Sinelon, 2)
247+
.stayActiveForNCycles(2);
248+
249+
quickPatterns.sameScene().addPattern(new qpLightning(20))
250+
.singleColor(CRGB(200, 0, 180))
251+
.activateWhenPatternPHasDeactivatedNTimes(WhiteLightning, 3) //After pattern p has activated 3 times... possible?
252+
.stayActiveForNCycles(4);
253+
254+
// ----- End Scene 4
255+
256+
257+
}
258+
259+
void loop()
260+
{
261+
quickPatterns.show();
262+
263+
EVERY_N_MINUTES(1) {
264+
quickPatterns.nextScene();
265+
}
266+
}

library.properties

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
name=quickPatterns
2+
version=0.2
3+
author=Chris Brim <chris.brim@protonmail.com>
4+
maintainer=Chris Brim <chris.brim@protonmail.com>
5+
sentence=A FastLED based patterns manager for addressable LEDs (WS2812B, NeoPixels, etc.) that allows multiple animations to run simultaneously on the same strand of lights with configurable colors and timings.
6+
paragraph=The goal of quickPatterns is to provide makers a simple interface in code for building advanced light pattern configurations i.e. multiple patterns running simultaneously with timed and sequenced pattern activation.
7+
category=Display
8+
url=https://github.com/brimshot/quickPatterns
9+
includes=quickPatterns.h
10+
depends=FastLED

0 commit comments

Comments
 (0)