FastLED 3.9.15
Loading...
Searching...
No Matches
DemoReel100.ino
Go to the documentation of this file.
1// @filter: (memory is large)
2
6
7#include <FastLED.h>
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
18
19#define DATA_PIN 3
20//#define CLK_PIN 4
21#define LED_TYPE WS2811
22#define COLOR_ORDER GRB
23#define NUM_LEDS 64
25
26#define BRIGHTNESS 96
27#define FRAMES_PER_SECOND 120
28
29void setup() {
30 delay(3000); // 3 second delay for recovery
31
32 // tell FastLED about the LED strip configuration
34 //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
35
36 // set master brightness control
37 FastLED.setBrightness(BRIGHTNESS);
38}
39
40// Forward declarations for pattern functions
41void rainbow();
43void confetti();
44void sinelon();
45void juggle();
46void bpm();
47void nextPattern();
48void addGlitter(fract8 chanceOfGlitter);
49
50// List of patterns to cycle through. Each is defined as a separate function below.
51typedef void (*SimplePatternList[])();
53
54uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
55uint8_t gHue = 0; // rotating "base color" used by many of the patterns
56
57void loop()
58{
59 // Call the current pattern function once, updating the 'leds' array
61
62 // send the 'leds' array out to the actual LED strip
63 FastLED.show();
64 // insert a delay to keep the framerate modest
65 FastLED.delay(1000/FRAMES_PER_SECOND);
66
67 // do some periodic updates
68 EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow
69 EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically
70}
71
72#define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0]))
73
75{
76 // add one to the current pattern number, and wrap around at the end
78}
79
80void rainbow()
81{
82 // FastLED's built-in rainbow generator
84}
85
87{
88 // built-in FastLED rainbow, plus some random sparkly glitter
89 rainbow();
90 addGlitter(80);
91}
92
93void addGlitter( fract8 chanceOfGlitter)
94{
95 if( random8() < chanceOfGlitter) {
97 }
98}
99
100void confetti()
101{
102 // random colored speckles that blink in and fade smoothly
104 int pos = random16(NUM_LEDS);
105 leds[pos] += CHSV( gHue + random8(64), 200, 255);
106}
107
109{
110 // a colored dot sweeping back and forth, with fading trails
112 int pos = beatsin16( 13, 0, NUM_LEDS-1 );
113 leds[pos] += CHSV( gHue, 255, 192);
114}
115
116void bpm()
117{
118 // colored stripes pulsing at a defined Beats-Per-Minute (BPM)
119 uint8_t BeatsPerMinute = 62;
120 CRGBPalette16 palette = PartyColors_p;
121 uint8_t beat = beatsin8( BeatsPerMinute, 64, 255);
122 for( int i = 0; i < NUM_LEDS; i++) { //9948
123 leds[i] = ColorFromPalette(palette, gHue+(i*2), beat-gHue+(i*10));
124 }
125}
126
127void juggle() {
128 // eight colored dots, weaving in and out of sync with each other
130 uint8_t dothue = 0;
131 for( int i = 0; i < 8; i++) {
132 leds[beatsin16( i+7, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255);
133 dothue += 32;
134 }
135}
void setup()
void loop()
#define COLOR_ORDER
#define NUM_LEDS
fl::CRGB leds[NUM_LEDS]
#define BRIGHTNESS
uint8_t pos
Definition Blur.ino:11
#define DATA_PIN
Definition ClientReal.h:82
void nextPattern()
void rainbowWithGlitter()
uint8_t gCurrentPatternNumber
#define ARRAY_SIZE(A)
void bpm()
void juggle()
void rainbow()
#define FRAMES_PER_SECOND
void(* SimplePatternList[])()
uint8_t gHue
SimplePatternList gPatterns
void addGlitter(fract8 chanceOfGlitter)
void confetti()
void sinelon()
FL_DISABLE_WARNING_PUSH FL_DISABLE_WARNING_GLOBAL_CONSTRUCTORS CFastLED FastLED
Global LED strip management instance.
UINumberField palette("Palette", 0, 0, 2)
#define LED_TYPE
void fadeToBlackBy(CRGB *leds, fl::u16 num_leds, fl::u8 fadeBy)
CRGB ColorFromPalette(const CRGBPalette16 &pal, fl::u8 index, fl::u8 brightness, TBlendType blendType)
void fill_rainbow(CRGB *targetArray, int numToFill, fl::u8 initialhue, fl::u8 deltahue=5) FL_NOEXCEPT
Fill a range of LEDs with a rainbow of colors.
Definition fill.cpp.hpp:29
@ TypicalLEDStrip
Typical values for SMD5050 LEDs.
Definition color.h:15
fl::hsv8 CHSV
Definition chsv.h:11
fl::CRGB CRGB
Definition crgb.h:25
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
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
u8 fract8
Fixed-Point Fractional Types.
Definition s16x16x4.h:161
@ White
<div style='background:#FFFFFF;width:4em;height:4em;'></div>
Definition crgb.h:646