-
Notifications
You must be signed in to change notification settings - Fork 46
/
fadeToBlackBy_example2.ino
92 lines (81 loc) · 2.16 KB
/
fadeToBlackBy_example2.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
//***************************************************************
// Fade up and down using fadeToBlackBy().
//
// Showing how fadeToBlackBy can also be used to fade up from
// black to colors. Maybe less common to do it this way, but
// it's an option.
//
// Marc Miller, Oct 2021
//***************************************************************
#include "FastLED.h"
#define DATA_PIN 11
#define CLOCK_PIN 13
#define LED_TYPE LPD8806
#define COLOR_ORDER GRB
#define NUM_LEDS 32
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
//---------------------------------------------------------------
void setup() {
Serial.begin(115200); // Allows serial monitor output
delay(1500); // startup delay
FastLED.addLeds<LED_TYPE,DATA_PIN,CLOCK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
FastLED.clear();
FastLED.show();
Serial.println("\nSetup done. \n");
}
//---------------------------------------------------------------
void loop() {
static uint8_t STATE = 1; // starting State
static uint8_t fadeAmount = 0; // current fade amount
static unsigned long previousMillis;
static uint8_t startHue;
EVERY_N_MILLISECONDS(30) {
startHue++;
}
EVERY_N_MILLISECONDS(50) {
switch (STATE) {
case 1:
{
fadeAmount++; // fading out
if (fadeAmount == 255) {
STATE = 2;
previousMillis = millis();
}
}
break;
case 2:
{
if (millis() - previousMillis > 1600) {
STATE = 3;
}
}
break;
case 3:
{
fadeAmount--; // fading in
if (fadeAmount == 0) {
STATE = 4;
previousMillis = millis();
}
}
break;
case 4:
{
if (millis() - previousMillis > 1000) {
STATE = 1;
}
}
break;
default:
break;
}
//Serial.println(fadeAmount);
}
fill_rainbow(leds, NUM_LEDS, startHue, NUM_LEDS/2);
for (uint8_t i = 0; i < NUM_LEDS/2; i++) {
leds[i].fadeToBlackBy(fadeAmount);
}
FastLED.show();
}