-
Notifications
You must be signed in to change notification settings - Fork 174
/
Copy pathrainbow_march.ino
77 lines (41 loc) · 2.6 KB
/
rainbow_march.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
/* rainbow_march
By: Andrew Tuline
Date: Nov, 2014
Updated: June, 2018
Update:
1.1 Remove original delay and added EVERY_N_MILLISECONDS
1.2 Remove EVERY_N_MILLISECONDS and use millis() for timing. Also demonstrate beat8 and beatsin8.
Description
Rainbow marching up the strand. Very basic, but oh so popular. Oh look, we don't need to add a 'wheel' routine.
If you want something really funky, try generating sequences with palettes, especially palettes you can change on the flly.
*/
#include "FastLED.h" // FastLED library.
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
// Fixed definitions cannot change on the fly.
#define LED_DT 12 // Serial data pin
#define LED_CK 11 // Clock pin for WS2801 or APA102
#define COLOR_ORDER BGR // It's GRB for WS2812B and GBR for APA102
#define LED_TYPE APA102 // What kind of strip are you using (APA102, WS2801 or WS2812B)?
#define NUM_LEDS 60 // Number of LED's
// Initialize changeable global variables.
uint8_t max_bright = 255; // Overall brightness definition. It can be changed on the fly.
struct CRGB leds[NUM_LEDS]; // Initialize our LED array.
void setup() {
Serial.begin(115200);
// LEDS.addLeds<LED_TYPE, LED_DT, COLOR_ORDER>(leds, NUM_LEDS); // For WS2812B
LEDS.addLeds<LED_TYPE, LED_DT, LED_CK, COLOR_ORDER>(leds, NUM_LEDS); // For APA102 or WS2801
FastLED.setBrightness(max_bright);
FastLED.setMaxPowerInVoltsAndMilliamps(5, 1000); // FastLED 2.1 Power management set at 5V, 500mA
} // setup()
void loop () {
rainbow_march(200, 10);
FastLED.show();
} // loop()
void rainbow_march(uint8_t thisdelay, uint8_t deltahue) { // The fill_rainbow call doesn't support brightness levels.
uint8_t thishue = millis()*(255-thisdelay)/255; // To change the rate, add a beat or something to the result. 'thisdelay' must be a fixed value.
// thishue = beat8(50); // This uses a FastLED sawtooth generator. Again, the '50' should not change on the fly.
// thishue = beatsin8(50,0,255); // This can change speeds on the fly. You can also add these to each other.
fill_rainbow(leds, NUM_LEDS, thishue, deltahue); // Use FastLED's fill_rainbow routine.
} // rainbow_march()