Is there a way to call the color as an assignable variable in a CRGB line:
leds = CRGB:: Orange;
replaced with
myVariable = Orange;
leds = CRGB:: myVariable;
if so what would be the data type?
Is there a way to call the color as an assignable variable in a CRGB line:
leds = CRGB:: Orange;
replaced with
myVariable = Orange;
leds = CRGB:: myVariable;
if so what would be the data type?
PaulRB answered my same question here.
Also, one of the sample sketches shows how colors are defined and passed to functions:
/*
****************************************************************
* fastLED_Cylon.ino
*
* Example of defining a CRGB color using Hex,
* and passing that to a function.
*
* Marc Miller, Feb 2017
****************************************************************
*/
#include "FastLED.h"
#define DATA_PIN D1
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 251
#define BRIGHTNESS 200
#define FRAMES_PER_SECOND 120
CRGB leds[NUM_LEDS];
#define MGPu CRGB(0x8010ff) // Mardi Gras Purple
#define MGGr CRGB(0x2cb004) // Green
#define MGGo CRGB(0xff4a00) // Gold
//---------------------------------------------------------------
void setup() {
Serial.begin(115200); // Allows serial monitor output (check baud rate)
delay(3000); // 3 second delay for recovery
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(BRIGHTNESS);
}
//---------------------------------------------------------------
void loop() {
cylon(MGPu); // Purple. (Call cylon function with this color.)
//cylon(MGGr); // Green
//cylon(MGGo); // Gold
}
//---------------------------------------------------------------
// ========================== cylon ==========================
void cylon(CRGB streakcolor) {
// Forward
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = streakcolor;
FastLED.show();
fadeall();
delay(10);
}
// Reverse
for (int i = (NUM_LEDS) - 1; i >= 0; i--) {
leds[i] = streakcolor;
FastLED.show();
fadeall();
delay(10);
}
}
// ========================== fadeall ==========================
void fadeall() {
for (int i = 0; i < NUM_LEDS; i++) {
leds[i].nscale8(250);
}
}
Perfect! Thank you!