FastLED 3.10.8
Loading...
Searching...
No Matches
demoreel100.h
Go to the documentation of this file.
1#pragma once
2
3#include "fl/stl/noexcept.h"
4
5#include "fl/fx/fx1d.h"
6
7namespace fl {
8
9// FastLED "100-lines-of-code" demo reel, showing just a few
10// of the kinds of animation patterns you can quickly and easily
11// compose using FastLED.
12//
13// This example also shows one easy way to define multiple
14// animations patterns and have them automatically rotate.
15//
16// -Mark Kriegsman, December 2014
17
19
20class DemoReel100 : public Fx1d {
21 public:
22 DemoReel100(u16 num_leds) FL_NO_EXCEPT : Fx1d(num_leds) {}
23
24 void draw(DrawContext context) FL_NO_EXCEPT override {
25 fl::span<CRGB> leds = context.leds;
26 if (leds.empty() || mNumLeds == 0) {
27 return;
28 }
29 if (start_time == 0) {
31 }
32
33 // Call the current pattern function once, updating the 'leds' array
35
36 // do some periodic updates
38 hue++;
39 } // slowly cycle the "base color" through the rainbow
40 EVERY_N_SECONDS(10) { nextPattern(); } // change patterns periodically
41 }
42
43 fl::string fxName() const FL_NO_EXCEPT override { return "DemoReel100"; }
44
45 private:
47 u8 hue = 0;
48 unsigned long start_time = 0;
49
51 // add one to the current pattern number, and wrap around at the end
53 (current_pattern_number + 1) % 6; // 6 is the number of patterns
54 }
55
57 switch (current_pattern_number) {
58 case 0:
60 break;
61 case 1:
63 break;
64 case 2:
66 break;
67 case 3:
69 break;
70 case 4:
71 juggle(leds);
72 break;
73 case 5:
74 bpm(leds);
75 break;
76 }
77 }
78
80 // FastLED's built-in rainbow generator
82 }
83
85 // built-in FastLED rainbow, plus some random sparkly glitter
87 addGlitter(80, leds);
88 }
89
91 if (random8() < chanceOfGlitter) {
93 }
94 }
95
97 // random colored speckles that blink in and fade smoothly
99 int pos = random16(mNumLeds);
100 leds[pos] += CHSV(hue + random8(64), 200, 255);
101 }
102
104 // a colored dot sweeping back and forth, with fading trails
105 fadeToBlackBy(leds, 20);
106 int pos = beatsin16(13, 0, mNumLeds - 1);
107 leds[pos] += CHSV(hue, 255, 192);
108 }
109
111 // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
112 u8 BeatsPerMinute = 62;
113 CRGBPalette16 palette = PartyColors_p;
114 u8 beat = beatsin8(BeatsPerMinute, 64, 255);
115 for (u16 i = 0; i < mNumLeds; i++) {
116 leds[i] =
117 ColorFromPalette(palette, hue + (i * 2), beat - hue + (i * 10));
118 }
119 }
120
122 // eight colored dots, weaving in and out of sync with each other
123 fadeToBlackBy(leds, 20);
124 u8 dothue = 0;
125 for (u16 i = 0; i < 8; i++) {
126 leds[beatsin16(i + 7, 0, mNumLeds - 1)] |= CHSV(dothue, 200, 255);
127 dothue += 32;
128 }
129 }
130};
131
132} // namespace fl
CRGB leds[1]
uint8_t pos
Definition Blur.ino:11
void rainbowWithGlitter()
void bpm()
void juggle()
void rainbow()
void confetti()
void sinelon()
UINumberField palette("Palette", 0, 0, 2)
void addGlitter(fract8 chanceOfGlitter, fl::span< CRGB > leds) FL_NO_EXCEPT
Definition demoreel100.h:90
void draw(DrawContext context) FL_NO_EXCEPT override
Definition demoreel100.h:24
void confetti(fl::span< CRGB > leds) FL_NO_EXCEPT
Definition demoreel100.h:96
void sinelon(fl::span< CRGB > leds) FL_NO_EXCEPT
void rainbow(fl::span< CRGB > leds) FL_NO_EXCEPT
Definition demoreel100.h:79
void runPattern(fl::span< CRGB > leds) FL_NO_EXCEPT
Definition demoreel100.h:56
void rainbowWithGlitter(fl::span< CRGB > leds) FL_NO_EXCEPT
Definition demoreel100.h:84
DemoReel100(u16 num_leds) FL_NO_EXCEPT
Definition demoreel100.h:22
void nextPattern() FL_NO_EXCEPT
Definition demoreel100.h:50
unsigned long start_time
Definition demoreel100.h:48
fl::string fxName() const FL_NO_EXCEPT override
Definition demoreel100.h:43
void bpm(fl::span< CRGB > leds) FL_NO_EXCEPT
void juggle(fl::span< CRGB > leds) FL_NO_EXCEPT
Fx1d(u16 numLeds) FL_NO_EXCEPT
Definition fx1d.h:13
u16 mNumLeds
Definition fx.h:53
LIB8STATIC u16 beatsin16(accum88 beats_per_minute, u16 lowest=0, u16 highest=65535, u32 timebase=0, u16 phase_offset=0) FL_NO_EXCEPT
Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
Definition beat.h:84
LIB8STATIC u8 beatsin8(accum88 beats_per_minute, u8 lowest=0, u8 highest=255, u32 timebase=0, u8 phase_offset=0) FL_NO_EXCEPT
Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
Definition beat.h:105
void fill_rainbow(CRGB *targetArray, int numToFill, u8 initialhue, u8 deltahue) FL_NO_EXCEPT
Fill a range of LEDs with a rainbow of colors.
Definition fill.cpp.hpp:30
fl::hsv8 CHSV
Definition chsv.h:11
const TProgmemRGBPalette16 PartyColors_p
HSV color ramp: blue, purple, pink, red, orange, yellow (and back).
LIB8STATIC fl::u16 random16() FL_NO_EXCEPT
Generate a 16-bit random number.
Definition random8.h:63
LIB8STATIC fl::u8 random8() FL_NO_EXCEPT
Generate an 8-bit random number.
Definition random8.h:53
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1045
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
Definition lib8tion.h:1010
unsigned char u8
Definition stdint.h:131
u8 u8 fract8 blur_amount FL_NO_EXCEPT
Definition blur.h:186
fl::u32 millis() FL_NO_EXCEPT
Universal millisecond timer - returns milliseconds since system startup.
void fadeToBlackBy(CRGB *leds, fl::u16 num_leds, fl::u8 fadeBy) FL_NO_EXCEPT
u8 fract8
Fixed-Point Fractional Types.
Definition stdint.h:160
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType) FL_NO_EXCEPT
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:577
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:653