I have 2 questions. How do I define my own colors? I'd like to look at the specification for CRGB but have gotten lost in GitHub.
I would also like to define a CRGB variable so I could pass the LED colors into a function as in:
Any comments suggestions are welcome.
BTW, there is a lot more code which goes with this but right now I just trying to figure out the syntax for defining a CRGB and how to define a CRGB variable.
Here is ALL the code. It is for 2 APA102C LED strips. One is 240LEDs and the other is 120LEDs. They are running a "cyclon " pattern.
Or are supposed to be. I took the loop code from a program using Adafruit (because FastLed won't run on a Giga) and modified it to run using FastLed. I have the basics of the program working with one strip. Here's the code so far:
#include <FastLED.h>
#define NUM_LEDS1 240
#define NUM_LEDS2 120
#define DATA_PIN1 4
#define CLOCK_PIN1 5
#define DATA_PIN2 6
#define CLOCK_PIN2 7
#define c_red CRGB::Red
#define b_red CRGB::Black
#define c_blu 0x0000FF
#define b_blu 0x000001
#define c_grn 0xFF0000
#define b_grn 0x010000
#define c_wht 0xFFFFFF
#define b_wht 0x010101
int flag = true;
int lb = 121;//large back end rev counter l in the for loop is the large counter
int s = 61; //small counter
int sb = 61; //small back end counter
// Define the array of leds
CRGB l_leds[NUM_LEDS1];
CRGB u_leds[NUM_LEDS2];
void cylon(){
//foward
flag = true;
lb = 240;
s = 0;
sb = 120;
for(int l=0;l<121;l++){
l_leds[l] = c_red; //this will be the foreground color passed in
l_leds[lb] = c_red;
l_leds[l-4] = b_red; //this will be the background color passed in
l_leds[lb+4] = b_red;
if (flag){
u_leds[s] = c_red;
u_leds[sb] = c_red;
u_leds[s-4] = b_red;
u_leds[sb+4] = b_red;
flag = !flag;
s++;
sb--;
} else flag = true;
FastLED.show();
lb--;
delay(0);
}
//backward
flag = true;
lb = 121;
s = 61;
sb = 61;
for(int l = 120;l > 0;l--){
l_leds[l] = c_red;
l_leds[lb] = c_red;
l_leds[l+4] = b_red;
l_leds[lb-4] = b_red;
if (flag){
u_leds[s] = c_red;
u_leds[sb] = c_red;
u_leds[s+4] = b_red;
u_leds[sb-4] = b_red;
flag = !flag;
sb++;
s--;
} else flag = true;
FastLED.show();
lb++;
delay(0);
}
}
void setup() {
FastLED.addLeds<APA102, DATA_PIN1, CLOCK_PIN1, BGR>(l_leds, NUM_LEDS1);
FastLED.addLeds<APA102, DATA_PIN2, CLOCK_PIN2, BGR>(u_leds, NUM_LEDS2);
}
void loop() {
cylon(); //need 2 CRGB variables HERE. One for foreground, one for background
}
You are already defining the colors correctly, the pre-defined colors in FastLED are actually an enum in pixeltypes.h, with red being the following:
Red=0xFF0000,
The type of the variable is CRGB, same as is used to define the array for the leds. CRGB is actually a struct, which allows you to access the individual red/green/blue components. Passing to a function is fairly straightforward:
#define c_red CRGB::Red
#define c_blue CRGB::Blue
CRGB color;
void change_strip_color(CRGB CRGBvariable) {
for (int x = 0; x < 21; x++) {
leds[x] = CRGBvariable;
}
}
///////////////////////////////
if (digitalRead(pinx)) {
color = c_red;
}
else {
color = c_blue;
}
change_strip_color(color);
I've always made minimal use of the features of FastLED and Adafruit's similar neopixel library.
Unsigned longs work fine for talking about color as you have seen.
Fun:
Write a sketch to continuously read and report the values from three potentiometers, mapped to 0 - 255, which are used to set the r, g and b components of the LEDs.
So,you can put them where they are gonna go, and dial around endlessly tinkering with the exact color, with an eye towards selecting nice colors and levels of brightness.
Assign them to manifest constants of your own and you done.