FastLED 3.9.15
Loading...
Searching...
No Matches
demoreel100.h
Go to the documentation of this file.
1#pragma once
2
3#include "FastLED.h"
4#include "fl/namespace.h"
5#include "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(uint16_t num_leds) : Fx1d(num_leds) {}
23
24 void draw(DrawContext context) override {
25 CRGB *leds = context.leds;
26 if (leds == nullptr || mNumLeds == 0) {
27 return;
28 }
29 if (start_time == 0) {
30 start_time = millis();
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::Str fxName() const override { return "DemoReel100"; }
44
45 private:
47 uint8_t hue = 0;
48 unsigned long start_time = 0;
49
50 void nextPattern() {
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
79 void rainbow(CRGB *leds) {
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
90 void addGlitter(fract8 chanceOfGlitter, CRGB *leds) {
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
106 int pos = beatsin16(13, 0, mNumLeds - 1);
107 leds[pos] += CHSV(hue, 255, 192);
108 }
109
110 void bpm(CRGB *leds) {
111 // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
112 uint8_t BeatsPerMinute = 62;
113 CRGBPalette16 palette = PartyColors_p;
114 uint8_t beat = beatsin8(BeatsPerMinute, 64, 255);
115 for (uint16_t i = 0; i < mNumLeds; i++) {
116 leds[i] =
117 ColorFromPalette(palette, hue + (i * 2), beat - hue + (i * 10));
118 }
119 }
120
121 void juggle(CRGB *leds) {
122 // eight colored dots, weaving in and out of sync with each other
124 uint8_t dothue = 0;
125 for (uint16_t 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[NUM_LEDS]
Definition Apa102.ino:11
uint8_t pos
Definition Blur.ino:11
void rainbowWithGlitter()
void bpm()
void juggle()
void rainbow()
void confetti()
void sinelon()
central include file for FastLED, defines the CFastLED class/object
UINumberField palette("Palette", 0, 0, 2)
void confetti(CRGB *leds)
Definition demoreel100.h:96
fl::Str fxName() const override
Definition demoreel100.h:43
void sinelon(CRGB *leds)
DemoReel100(uint16_t num_leds)
Definition demoreel100.h:22
void draw(DrawContext context) override
Definition demoreel100.h:24
void addGlitter(fract8 chanceOfGlitter, CRGB *leds)
Definition demoreel100.h:90
void bpm(CRGB *leds)
void rainbow(CRGB *leds)
Definition demoreel100.h:79
void runPattern(CRGB *leds)
Definition demoreel100.h:56
unsigned long start_time
Definition demoreel100.h:48
uint8_t current_pattern_number
Definition demoreel100.h:46
void juggle(CRGB *leds)
void rainbowWithGlitter(CRGB *leds)
Definition demoreel100.h:84
Fx1d(uint16_t numLeds)
Definition fx1d.h:14
uint16_t mNumLeds
Definition fx.h:53
_DrawContext DrawContext
Definition fx.h:21
Definition str.h:388
LIB8STATIC uint16_t beatsin16(accum88 beats_per_minute, uint16_t lowest=0, uint16_t highest=65535, uint32_t timebase=0, uint16_t phase_offset=0)
Generates a 16-bit sine wave at a given BPM that oscillates within a given range.
Definition lib8tion.h:939
LIB8STATIC uint8_t beatsin8(accum88 beats_per_minute, uint8_t lowest=0, uint8_t highest=255, uint32_t timebase=0, uint8_t phase_offset=0)
Generates an 8-bit sine wave at a given BPM that oscillates within a given range.
Definition lib8tion.h:957
void fill_rainbow(struct CRGB *targetArray, int numToFill, uint8_t initialhue, uint8_t deltahue)
Fill a range of LEDs with a rainbow of colors.
Definition fill.cpp:29
uint8_t fract8
ANSI: unsigned short _Fract.
Definition types.h:36
const TProgmemRGBPalette16 PartyColors_p
HSV color ramp: blue, purple, pink, red, orange, yellow (and back).
LIB8STATIC uint16_t random16()
Generate a 16-bit random number.
Definition random8.h:56
LIB8STATIC uint8_t random8()
Generate an 8-bit random number.
Definition random8.h:46
#define EVERY_N_MILLISECONDS(N)
Alias for EVERY_N_MILLIS.
Definition lib8tion.h:1341
#define EVERY_N_SECONDS(N)
Checks whether to execute a block of code every N seconds.
Definition lib8tion.h:1306
Implements the FastLED namespace macros.
CRGB ColorFromPalette(const CRGBPalette16 &pal, uint8_t index, uint8_t brightness, TBlendType blendType)
void fadeToBlackBy(CRGB *leds, uint16_t num_leds, uint8_t fadeBy)
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
#define FASTLED_SMART_PTR(type)
Definition ptr.h:31
Representation of an HSV pixel (hue, saturation, value (aka brightness)).
Definition chsv.h:16
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:640
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:55