-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathevery_n_timer_variable_2.ino
More file actions
74 lines (58 loc) · 2.11 KB
/
every_n_timer_variable_2.ino
File metadata and controls
74 lines (58 loc) · 2.11 KB
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
// 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
// Aug 2025 - Removed the two FastLED.show() calls
// inside the if statements and put a
// single show() at the bottom of the loop.
// - Reduced max brightness since this turns
// on all the pixels at once.
//---------------------------------------------------------------
#include "FastLED.h"
#define LED_TYPE LPD8806
#define DATA_PIN 11
#define CLOCK_PIN 13
#define NUM_LEDS 32
#define COLOR_ORDER GRB
#define BRIGHTNESS 64
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, CLOCK_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(2500); // time [milliseconds] to display solid before fading
fill_solid(leds, NUM_LEDS, CHSV(gHue, 255, 255));
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(10) {
fadeToBlackBy(leds, NUM_LEDS, 1); // fade out
}
}
FastLED.show();
} // end main loop