cookbook/getting-started/concepts.md
Difficulty Level: ⭐ Beginner Time to Complete: 20 minutes Prerequisites: None (this is your starting point!)
You'll Learn:
Core ideas behind LED programming with FastLED.
Each LED in your strip has an index (position) starting from 0.
LED Strip: [0] [1] [2] [3] [4] [5] ... [59]
^ ^
First Last
You control LEDs by setting color values in an array:
CRGB leds[60]; // Array for 60 LEDs
leds[0] = CRGB::Red; // First LED is red
leds[5] = CRGB::Blue; // Sixth LED is blue
FastLED supports two main color models:
Each color channel ranges from 0-255:
CRGB color = CRGB(255, 0, 0); // Red
CRGB color = CRGB(0, 255, 0); // Green
CRGB color = CRGB(0, 0, 255); // Blue
CRGB color = CRGB(255, 255, 255); // White
CHSV hsv1 = CHSV(0, 255, 255); // Red
CHSV hsv2 = CHSV(96, 255, 255); // Green
CHSV hsv3 = CHSV(160, 255, 255); // Blue
// Automatic conversion to RGB
leds[0] = hsv1;
Why use HSV?
Every FastLED program follows this pattern:
void setup() {
// 1. Initialize FastLED (runs once)
FastLED.addLeds<LED_TYPE, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(50);
}
void loop() {
// 2. Calculate/update LED colors
leds[0] = CRGB::Red;
// 3. Send colors to LEDs
FastLED.show();
// 4. Optional: delay or manage frame rate
delay(20);
}
Key points:
setup() runs once at startup - configure your LEDs hereloop() runs repeatedly - update your LED colors hereFastLED.show() to actually update the physical LEDsleds[] array are not visible until you call FastLED.show()Tell FastLED about your hardware:
#define LED_PIN 5 // Data pin number
#define NUM_LEDS 60 // Number of LEDs
#define LED_TYPE WS2812B // Your LED strip type
#define COLOR_ORDER GRB // Color channel order
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
}
Common LED types:
WS2812B - Most common (NeoPixel)APA102 - DotStar (requires clock pin)SK6812 - Similar to WS2812BCommon color orders:
GRB - WS2812B (most common)RGB - Some WS2811BGR - APA102If your colors are wrong, try different COLOR_ORDER values.
Control overall brightness (0-255):
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(50); // 0-255 (50 = ~20% brightness)
}
Tip: Start with low brightness (50) when testing to avoid eye strain and reduce power draw.
Use static variables to remember values between loop iterations:
void loop() {
static uint8_t hue = 0; // Remembers value across loops
leds[0] = CHSV(hue, 255, 255);
FastLED.show();
hue++; // Increment for next loop
}
Without static, the variable resets to 0 every loop.
Now that you understand the basics: