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