-
Notifications
You must be signed in to change notification settings - Fork 46
/
every_n_timer_variable_2.ino
69 lines (53 loc) · 1.78 KB
/
every_n_timer_variable_2.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
// EVERY_N variable timer example
// Turns all pixels on for a short time then fades them out
// to black. Holds black for a short time and then repeats
// On/Fade/Off pattern.
//
// A new hue is displayed each time.
//
//
// Marc Miller, June 2020
//---------------------------------------------------------------
#include "FastLED.h"
#define LED_TYPE WS2812B
#define DATA_PIN 11
#define NUM_LEDS 12
#define COLOR_ORDER GRB
#define BRIGHTNESS 255
CRGB leds[NUM_LEDS];
static uint8_t gHue;
static boolean P = 0;
//---------------------------------------------------------------
void setup() {
Serial.begin(115200);
delay(1500); // startup delay
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS)
.setCorrection( TypicalLEDStrip );
FastLED.setBrightness(BRIGHTNESS);
Serial.println("Setup done. \n");
}
//---------------------------------------------------------------
void loop() {
EVERY_N_MILLISECONDS_I( timingObj, 1) {
// This initally defaults to 1 millisecond, but then will
// imediately use the timingObj.setPeriod times below.
// You can name "timingObj" anything you want.
P = !P; // toggle P between 0 and 1
if (P) {
timingObj.setPeriod(2000); // time to display solid before fading
fill_solid(leds, NUM_LEDS, CHSV(gHue, 255, 255));
FastLED.show();
Serial.print("fill_solid, hue: "); Serial.println(gHue);
} else {
timingObj.setPeriod(5000);
Serial.println("Fading out now...\n");
gHue = gHue + 42; // set a new hue
}
} // end of every_n variable timing
if (P == 0) {
EVERY_N_MILLISECONDS(15) {
fadeToBlackBy(leds, NUM_LEDS, 1); // fade out
FastLED.show();
}
}
} // end main loop