forked from marmilicious/FastLED_examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
multiple_animations.ino
127 lines (100 loc) · 3.51 KB
/
multiple_animations.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
/*********************************************************************/
// Example of running multiple animations/patterns at the same time
// on different parts of the same LED strip. Seperate "working" or
// "temporary" arrays are used for each section. Whenever one of
// these working arrays is updated then the data is copied to the
// "leds" array so it can be displayed.
//
// Animation A [ledsA] is running a chase effect.
// Animation B [ledsB] is cycling through the rainbow.
// Animation C [ledsC] is running a scanner/cylon type effect.
// Animation D [ledsD] is lighting up random pixels.
//
// Note that there is only one FastLED.show() call in the program.
//
//
// Marc Miller, April 2019
/*********************************************************************/
#include "FastLED.h"
#define LED_TYPE LPD8806
#define DATA_PIN 11
#define CLOCK_PIN 13
#define COLOR_ORDER GRB
#define MASTER_BRIGHTNESS 255
#define NUM_LEDS 32
//Note: numA thru numD values must add up to NUM_LEDS
#define numA 5 //pixels 0-4
#define numB 3 //pixels 5-7
#define numC 16 //pixels 8-23
#define numD 8 //pixels 24-31
CRGB leds[NUM_LEDS]; //what actually gets displayed
CRGB ledsA[numA]; //numA thru numD are "working" arrays
CRGB ledsB[numB];
CRGB ledsC[numC];
CRGB ledsD[numD];
/*********************************************************************/
void setup() {
Serial.begin(115200); //allow for output to serial monitor
delay(2500); //power up delay
FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(MASTER_BRIGHTNESS);
FastLED.clear();
Serial.println("setup done");
}//end_setup
/*********************************************************************/
void loop() {
//--------------Animation A--------------
static uint8_t color;
EVERY_N_MILLISECONDS(180) {
fadeToBlackBy( ledsA, numA, 230);
static uint8_t i = 0;
ledsA[i] = CHSV( color+random8(0,10), 160, 255 );
i++;
if (i == numA) { i = 0; } //reset
//copy ledsA data to leds
for (uint8_t i=0; i<numA; i++) { leds[i] = ledsA[i]; }
}
EVERY_N_SECONDS(2) {
color = random8();
}
//--------------Animation B--------------
const uint8_t delta = 255/numB/5;
static uint8_t count;
EVERY_N_MILLISECONDS(60) { count++; }
fill_rainbow(ledsB, numB, count, -1*delta );
//copy ledsB data to leds
for (uint8_t i=0; i<numB; i++) { leds[i+numA] = ledsB[i]; }
//--------------Animation C--------------
for (uint8_t i=0; i<numC; i++) {
uint8_t blue = (millis()/30)+(i*3);
if (blue < 128) {
ledsC[i] = CRGB(200, 0, 0);
} else {
ledsC[i] = CRGB(50, 0, blue);
}
}
fadeToBlackBy( ledsC, numC, 220);
uint8_t pos = beatsin8(20,0,numC-1);
ledsC[pos] = CRGB::Green;
//copy ledsC data to leds
for (uint8_t i=0; i<numC; i++) { leds[i+numA+numB] = ledsC[i]; }
//--------------Animation D--------------
EVERY_N_MILLISECONDS(400) {
for (uint8_t i=0; i<3; i++) { //lightup some random pixels
uint8_t pick = random8(numD);
static uint8_t hue;
ledsD[pick] = CHSV( hue, random8(128,200), random8(200,255) );
hue = hue + random8(4,8);
}
//copy ledsD data to leds
for (uint8_t i=0; i<numD; i++) { leds[i+numA+numB+numC] = ledsD[i]; }
}
EVERY_N_MILLISECONDS(200) {
uint8_t pick = random8(numD);
ledsD[pick] = CRGB::Black;
//copy ledsD data to leds
for (uint8_t i=0; i<numD; i++) { leds[i+numA+numB+numC] = ledsD[i]; }
}
//display all the updates on leds array
FastLED.show();
}//end_main_loop