@@ -25,204 +25,102 @@ SOFTWARE.
2525
2626
2727/* ************
28- Examples of using the qp library
28+ Demo reel using the quickPatterns library
2929
30- These are examples that tend to look better on bulb style lights,
31-
32- These are examples that tend to look better on flat strips of LEDs, making heavy use of negative space, state machine based patterns and
33-
34- These are examples intended for a matrix with
30+ These are examples that tend to look better on bulb style lights, making use of wave animations
3531**************/
3632
3733#include < FastLED.h>
3834#include < quickPatterns.h>
39- #include < qpAllPatterns .h>
35+ #include < qpSamplePatterns .h>
4036
4137#define CHIPSET WS2811
42- #define DATA_PIN 8 // pin 11 is hardware SPI on Teensy 3.x and ATMega328P based Arduino
43- #define NUM_LEDS_PER_STRIP 50
44- #define NUM_STRIPS 2
45- #define NUM_LEDS NUM_LEDS_PER_STRIP*NUM_STRIPS
38+ #define DATA_PIN 8
39+ #define NUM_LEDS 100
4640#define BRIGHTNESS 32
4741#define COLOR_ORDER RGB // GRB for WS2812, RGB for WS2811
4842
49- /*
50- #define LIGHTSHOW(NAME) void NAME(quickPatterns &qp) { \
51- // static quickPatterns *qp = qp;
52-
53- */
54-
55- /*
56- #define AT(TICKS) if(doTicks(controller, TICKS)) //if((qp->getTicks() == TICKS) && (previousTick != TICKS))
57-
58- #define LIGHTSHOW(NAME) void NAME(quickPatterns &controller)
59- */
60-
61- // #define AT(TICKS) qpShow.addEvent()->conditionalFunction = []() { return true; };
43+ #define TICKLENGTH 25
6244
6345// Declare master set of leds for FastLED to write to
6446CRGB leds[NUM_LEDS];
6547
66- // Declare EasyLightStrand and pass in CRGB array
6748quickPatterns quickPatterns (leds, NUM_LEDS); // NUM_STRIPS*NUM_LEDS_PER_STRIP);
68-
69- // qpShow *qps = new qpShow();
70-
71- /*
72- bool funcoTime() {
73- return true;
74- }
75- */
76-
7749void setup () {
7850
79- // quickPatterns controller(leds, NUM_LEDS);
80- /*
81- qps->addEvent()->conditionalFunction = [](quickPatterns *controller) { return controller->isAtTick(300); };
82- qps->currentEvent()->eventCode = [](quickPatterns *controller)
83- */
84-
8551 delay (3000 ); // Recovery delay
8652
87- // Serial.begin(9600);
88-
89- randomSeed (analogRead (1 ));
90-
9153 // ~ Configure FastLED
9254
9355 FastLED.addLeds <CHIPSET, 8 , COLOR_ORDER>(leds, NUM_LEDS)
9456 .setCorrection (TypicalLEDStrip)
9557 .setDither (BRIGHTNESS < 255 );
9658
9759
98- // FastLED.addLeds<CHIPSET, 8, COLOR_ORDER>(leds, 0, 50);
99- /*
100- .setCorrection(TypicalLEDStrip)
101- .setDither(BRIGHTNESS < 255);
102- */
103-
104- // FastLED.addLeds<CHIPSET, 9, COLOR_ORDER>(leds, 50, 100);
105- /*
106- .setCorrection(TypicalLEDStrip)
107- .setDither(BRIGHTNESS < 255);
108- */
109-
11060 FastLED.setBrightness (BRIGHTNESS);
11161 FastLED.setMaxPowerInVoltsAndMilliamps (5 , 450 );
11262
11363 FastLED.clear ();
11464
115- // ~ Setup
11665
66+ // ~ Configure quickPatterns
67+
68+ // Due to a potential latching issue when writing data, we use a hard delay for timing with the ESP8266
11769 #ifdef ESP8266
11870 quickPatterns.setTickMillis (0 );
11971 #endif
12072
12173 #ifndef ESP8266
122- quickPatterns.setTickMillis (25 );
74+ quickPatterns.setTickMillis (TICKLENGTH );
12375 #endif
12476
125- // ~ Scene 0 - scene 0 demonstrates simultaneous patterns, timed activation and two options for dynamically changing colors
126-
127- /*
128- quickPatterns.addPattern(new qpJuggle())
129- .chooseColorSequentiallyFromPalette(CRGBPalette16(CRGB::Green, CRGB::Blue))
130- .changeColorEveryNTicks(6)
131- .drawEveryNTicks(4);
132- quickPatterns.sameLayer().continuallyFadeLayerBy(20);
133-
134- quickPatterns.addPattern(new qpRandomBar(10))
135- .singleColor(CRGB::Yellow)
136- .activatePeriodicallyEveryNTicks(10)
137- .stayActiveForNFrames(1);
138- quickPatterns.sameLayer().continuallyFadeLayerBy(20).setLayerBrush(COMBINE);
139- */
140-
141- /*
142- quickPatterns.addPattern(new qpFeathers(5))
143- .drawEveryNTicks(3)
144- .activatePeriodicallyEveryNTicks(100)
145- .stayActiveForNCycles(1)
146- .chooseColorRandomlyFromPalette(RainbowColors_p)
147- .changeColorEveryNCycles(1);
148- quickPatterns.sameLayer().continuallyFadeLayerBy(20).setLayerBrush(ADD);
149- */
150-
151- /*
152- quickPatterns.addPattern(new qpJuggle())
153- .chooseColorSequentiallyFromPalette(CRGBPalette16(CRGB::Yellow, CRGB::Pink))
154- .changeColorEveryNTicks(10)
155- .drawEveryNTicks(4); //slowing down our updates gives a wider spread to the juggle effect
156- quickPatterns.sameLayer().continuallyFadeLayerBy(20);
157-
158-
159- quickPatterns.addPattern(new qpBouncingPulse(8))
160- .deactivate();
161- */
162-
163- // qps->currentEvent->conditionalFunction = &funcoTime;
164-
165- /*
166- quickPatterns.addPattern(new qpPusher(10))
167- .singleColor(CRGB::RoyalBlue)
168- .drawEveryNTicks(2);
169- quickPatterns.sameLayer().continuallyFadeLayerBy(20);
170-
171- quickPatterns.addPattern(new qpPusher(6))
172- .singleColor(CRGB::Red);
173- quickPatterns.sameLayer().continuallyFadeLayerBy(20).setLayerBrush(ADD);
174-
175- return;
176- */
77+ // ~ Scene 0 - demonstrates simultaneous patterns, timed activation and two options for dynamically changing colors
17778
17879 // Each call to addPattern() automatically creates a new 'layer' on which that pattern is rendered which we can use to combine, blend and time independently
17980
180- // Layer one - a sine wave that moves back and forth along the strip. The wave color moves through the rainbow palette sequentially
81+ // sine wave that moves back and forth along the strip rainbow palette sequentially
18182 quickPatterns.addPattern (new qpSinelon (16 ))
18283 .chooseColorSequentiallyFromPalette (RainbowColors_p)
18384 .changeColorEveryNTicks (2 );
18485 // The sameLayer() function returns a reference to the last layer accessed. We are going to continually fade this layer's light such that old pixels fade away once rendered. Fade values are from 0-255
18586 quickPatterns.sameLayer ().continuallyFadeLayerBy (20 );
18687
187- // CRGB pulseColors[3] = {CRGB::Blue, CRGB::Yellow, CRGB::HotPink};
188- // Create a color set
88+ // create a color set
18989 CRGB *pulseColors = new CRGB[3 ];
19090 pulseColors[0 ] = CRGB::Blue;
19191 pulseColors[1 ] = CRGB::Yellow;
19292 pulseColors[2 ] = CRGB::Pink;
19393
194- // A small line of pixels that bounces back and forth along the strip - the color is from our set created above
94+ // small line of pixels that bounces back and forth
19595 quickPatterns.addPattern (new qpBouncingPulse (8 ))
19696 .chooseColorSequentiallyFromSet (pulseColors, 3 )
19797 .changeColorEveryNCycles (4 );
19898
199-
99+ // randomly activated lightning flashes
200100 quickPatterns.addPattern (new qpFlashRandomSection (10 ))
201- .singleColor (CRGB::White);
202-
203- quickPatterns.samePattern ().activatePeriodicallyEveryNTicks (100 , 200 )
101+ .singleColor (CRGB::White)
102+ .activatePeriodicallyEveryNTicks (100 , 200 )
204103 .stayActiveForNCycles (2 , 4 );
205104
206- // ** Scene 1 - scene 1 demonstrates timed activation and duration
207105
208- // Scenes are groups of layers + patterns that can be referenced as a unit. When we call addPattern() without the scene() function preceding it (as above), we automatically access scene 0
209- // To configure a set of scenes, simply prepend the scene() function before adding patterns with the id of the scene you want to manipulate
106+ // ~ Scene 1 - demonstrates timed activation and duration
210107
211- // Lay down a base juggle effect
108+ // juggle effect base layer
212109 quickPatterns.newScene ().addPattern (new qpJuggle ())
213110 .chooseColorSequentiallyFromPalette (ForestColors_p)
214111 .changeColorEveryNTicks (10 )
215112 .drawEveryNTicks (4 ); // slowing down our updates gives a wider spread to the juggle effect
216113 quickPatterns.sameLayer ().continuallyFadeLayerBy (20 );
217114
218- // Yellow sine wave that will activate randomly at intervals between 80 and 150 ticks. Once active, the pattern stays active for 50 ticks
115+ // sine wave activated randomly at intervals between 80 and 150 ticks. once active, stays active for 50 ticks. changes from blue to purple
219116 quickPatterns.sameScene ().addPattern (new qpBouncingPulse (20 ))
220117 .chooseColorSequentiallyFromPalette (CRGBPalette16 (CRGB::Blue, CRGB::Purple))
221118 .changeColorEveryNTicks (1 )
222119 .activatePeriodicallyEveryNTicks (80 , 150 )
223120 .stayActiveForNCycles (4 );
224121 quickPatterns.sameLayer ().continuallyFadeLayerBy (20 ).setLayerBrush (ADD);
225122
123+ // periodic yellow feathers
226124 quickPatterns.sameScene ().addPattern (new qpRandomBar (10 ))
227125 .singleColor (CRGB::Yellow)
228126 .activatePeriodicallyEveryNTicks (160 )
@@ -231,120 +129,55 @@ void setup() {
231129 quickPatterns.sameLayer ().continuallyFadeLayerBy (20 ).setLayerBrush (COMBINE);
232130
233131
234- // ** Scene 2 - scene 2 demonstrates two different layer brushes, ADD and SUBTRACT
132+ // ~ Scene 2 - demonstrates the MASK brush
235133
236- // Lay down a base rainbow gradient
237- /*
238- quickPatterns.scene(2).addPattern(new qpMovingGradient(OceanColors_p, 0))
239- .drawEveryNTicks(3);
240-
241- // Soft white confetti. Using the ADD brush to add this layers light to those below, we apply a sparkle effect on the underlying gradient colors
242- quickPatterns.scene(2).addPattern(new qpConfetti())
243- .singleColor(CRGB(64, 64, 64))
244- .drawEveryNTicks(4); //slower confetti reduces the busy-ness of the effect
245- quickPatterns.sameLayer().continuallyFadeLayerBy(30).setLayerBrush(ADD);
246-
247- // Roving negative space - by setting the pattern color to white and using the SUBTRACT brush to subtract this layer's light from those below, we can draw our pattern with negative space
248- quickPatterns.scene(2).addPattern(new qpWanderingLine(8))
249- .singleColor(CRGB::White);
250- quickPatterns.sameLayer().setLayerBrush(SUBTRACT);
251- */
252-
253-
254- // ~ Scene 3 - scene 3 demonstrates the MASK brush
255-
256- // Lay down a base layer of a moving rainbow gradient
134+ // rainbow gradient base layer
257135 quickPatterns.newScene ().addPattern (new qpMovingGradient (RainbowColors_p));
258136
259- // Add soft white confetti. Using the ADD brush to add this layers light to what's below which gives a popping sparkle effect and will leave sparkles as the mask fades
137+ // soft white confetti. Using the ADD brush to add this layers light to what's below which gives a popping sparkle effect and will leave sparkles as the mask fades
260138 quickPatterns.sameScene ().addPattern (new qpConfetti ())
261139 .singleColor (CRGB::White)
262140 .drawEveryNTicks (4 );
263141 quickPatterns.sameLayer ().continuallyFadeLayerBy (30 ).setLayerBrush (ADD);
264142
265- // Add a feather mask. Feathers illuminate the strand in sections,
143+ // feather mask periodically illuminates the strand in sections
266144 quickPatterns.sameScene ().addPattern (new qpFeathers (10 ))
267145 .singleColor (CRGB::White)
268146 .drawEveryNTicks (3 )
269147 .activatePeriodicallyEveryNTicks (50 , 200 )
270148 .stayActiveForNCycles (1 );
271149 quickPatterns.sameLayer ().setLayerBrush (MASK).continuallyFadeLayerBy (10 );
272150
273- // quickPatterns.playScene(3);
151+ // small pink runner on top
152+ quickPatterns.sameScene ().addPattern (new qpBouncingPulse (5 ))
153+ .singleColor (CRGB::HotPink);
154+
155+
156+ // ~ Scene 3 - demonstrates periodic pattern activation
157+
158+ // stop and go rainbow theater chase
159+ quickPatterns.newScene ().addPattern (new qpTheaterChase ())
160+ .drawEveryNTicks (3 )
161+ .chooseColorSequentiallyFromPalette (RainbowColors_p)
162+ .changeColorEveryNTicks (6 )
163+ .activatePeriodicallyEveryNTicks (25 , 75 )
164+ .stayActiveForNTicks (25 , 75 );
274165
275166}
276167
277168
278169void loop ()
279170{
280171
281- // myfunc(10);
282- // myFirstShow(qp);
283- // qps->playShow();
284172 quickPatterns.draw ();
285- /*
286- AT(100) {
287- Serial.println("Hit a boundary of 100 " + String(quickPatterns.getTicks()));
288- qp(0,1).stayActiveForNCycles(2)
289- .activate();
290- WHENDONE(qp(0,1)) {
291- qp(0,2).stayActiveForNCycles(1)
292- .activate();
293- }
294- }
295- AT(900) {
296-
297- }
298- */
299- // memcpy(leds, myLeds, sizeof(CRGB)*100);
300173 FastLED.show ();
301174
302175 #ifdef ESP8266
303- FastLED.delay (25 );
176+ FastLED.delay (TICKLENGTH );
304177 #endif
305178
306179 EVERY_N_SECONDS (30 ) {
307- // quickPatterns.playRandomScene();
308180 quickPatterns.nextScene ();
309181 }
310182
311183}
312-
313- /*
314- LIGHTSHOW(myFirstShow, qp) {
315- AT(0) {
316- qp(2, 0).setPalette(CRGBPalette16(CRGB::Yellow, CRGB::Orange));
317- quickPatterns.playScene(2);
318- }
319- AT(300) {
320- qp(2, 0).setPalette(CRGBPalette16(CRGB::Purple, CRGB::Blue));
321- }
322- AT(600) {
323- RESTARTLIGHTSHOW
324- }
325- }
326- */
327-
328- /*
329- LIGHTSHOW(myFirstShow) {
330- AT(300) {
331- controller(0, 1).singleColor(CRGB::Blue)
332- .stayActiveForNCycles(2)
333- .activate();
334- }
335- AT(900) {
336- controller(0).setPalette(CRGBPalette16(CRGB::Blue, CRGB::Purple));
337- }
338- AT(1000) {
339- controller(0, 1).singleColor(CRGB::Red)
340- .stayActiveForNCycles(4)
341- .activate();
342- }
343- }
344- */
345-
346- /*
347- LIGHTSHOW(myfunc, myparam) {
348- Serial.println("my param is" + String(myparam));
349- }
350- */
0 commit comments