FastLED 3.9.7
Loading...
Searching...
No Matches
RGBWEmulated.ino
1
2#include <FastLED.h>
3
4// How many leds in your strip?
5#define NUM_LEDS 10
6
7// For led chips like WS2812, which have a data line, ground, and power, you just
8// need to define DATA_PIN. For led chipsets that are SPI based (four wires - data, clock,
9// ground, and power), like the LPD8806 define both DATA_PIN and CLOCK_PIN
10// Clock pin only needed for SPI based chipsets when not using hardware SPI
11#define DATA_PIN 3
12
13// Define the array of leds
14CRGB leds[NUM_LEDS];
15
16// Time scaling factors for each component
17#define TIME_FACTOR_HUE 60
18#define TIME_FACTOR_SAT 100
19#define TIME_FACTOR_VAL 100
20
21Rgbw rgbw = Rgbw(
22 kRGBWDefaultColorTemp,
23 kRGBWExactColors, // Mode
24 W3 // W-placement
25);
26
27typedef WS2812<DATA_PIN, RGB> ControllerT; // RGB mode must be RGB, no re-ordering allowed.
28static RGBWEmulatedController<ControllerT, GRB> rgbwEmu(rgbw); // ordering goes here.
29
30void setup() {
31 Serial.begin(115200);
32 //FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS).setRgbw(RgbwDefault());
33 FastLED.addLeds(&rgbwEmu, leds, NUM_LEDS);
34 FastLED.setBrightness(128); // Set global brightness to 50%
35 delay(2000); // If something ever goes wrong this delay will allow upload.
36}
37
38void fillAndShow(CRGB color) {
39 for (int i = 0; i < NUM_LEDS; ++i) {
40 leds[i] = color;
41 }
42 FastLED.show();
43}
44
45// Cycle r,g,b,w. Red will blink once, green twice, ... white 4 times.
46void loop() {
47 static size_t frame_count = 0;
48 int frame_cycle = frame_count % 4;
49 frame_count++;
50
51 CRGB pixel;
52 switch (frame_cycle) {
53 case 0:
54 pixel = CRGB::Red;
55 break;
56 case 1:
57 pixel = CRGB::Green;
58 break;
59 case 2:
60 pixel = CRGB::Blue;
61 break;
62 case 3:
63 pixel = CRGB::White;
64 break;
65 }
66
67 for (int i = -1; i < frame_cycle; ++i) {
68 fillAndShow(pixel);
69 delay(200);
70 fillAndShow(CRGB::Black);
71 delay(200);
72 }
73 delay(1000);
74}
CFastLED FastLED
Global LED strip management instance.
Definition FastLED.cpp:45
central include file for FastLED, defines the CFastLED class/object
void setBrightness(uint8_t scale)
Set the global brightness scaling.
Definition FastLED.h:723
void show(uint8_t scale)
Update all our controllers with the current led colors, using the passed in brightness.
Definition FastLED.cpp:94
static CLEDController & addLeds(CLEDController *pLed, struct CRGB *data, int nLedsOrOffset, int nLedsIfOffset=0)
Add a CLEDController instance to the world.
Definition FastLED.cpp:79
WS2812 controller class.
Definition FastLED.h:190
@ W3
White is fourth.
Definition eorder.h:25
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54
@ White
Definition crgb.h:632
@ Green
Definition crgb.h:544
@ Blue
Definition crgb.h:498
@ Red
Definition crgb.h:608
@ Black
Definition crgb.h:496
Definition rgbw.h:28