cookbook/basic-patterns/solid-colors.md
Difficulty Level: ⭐ Beginner Time to Complete: 15-20 minutes Prerequisites: Core Concepts, First Example
You'll Learn:
Solid colors are the foundation of LED control. This pattern demonstrates how to fill your LED strip with a single color using FastLED's efficient fill functions.
Fill all LEDs with a single color:
// Fill entire strip
fill_solid(leds, NUM_LEDS, CRGB::Blue);
Fill a specific section of your strip:
// Fill range
fill_solid(&leds[10], 20, CRGB::Green); // LEDs 10-29
This fills 20 LEDs starting from index 10, effectively controlling LEDs 10 through 29.
Use HSV color space for more intuitive color selection:
// Fill with HSV
fill_solid(leds, NUM_LEDS, CHSV(160, 255, 255));
RGB (Red, Green, Blue) uses three channels 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
HSV (Hue, Saturation, Value) is often more intuitive:
CHSV hsv = CHSV(0, 255, 255); // Red
CHSV hsv = CHSV(96, 255, 255); // Green
CHSV hsv = CHSV(160, 255, 255); // Blue
// Convert HSV to RGB (automatic)
leds[0] = hsv;
Why use HSV?
FastLED provides convenient named colors:
leds[0] = CRGB::Red;
leds[1] = CRGB::Green;
leds[2] = CRGB::Blue;
leds[3] = CRGB::White;
leds[4] = CRGB::Yellow;
leds[5] = CRGB::Purple;
leds[6] = CRGB::Cyan;
leds[7] = CRGB::Black; // Off
#include <FastLED.h>
#define LED_PIN 5
#define NUM_LEDS 60
#define LED_TYPE WS2812B
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(50);
}
void loop() {
// Cycle through different solid colors
fill_solid(leds, NUM_LEDS, CRGB::Red);
FastLED.show();
delay(1000);
fill_solid(leds, NUM_LEDS, CRGB::Green);
FastLED.show();
delay(1000);
fill_solid(leds, NUM_LEDS, CRGB::Blue);
FastLED.show();
delay(1000);
// Fill different sections
fill_solid(&leds[0], 20, CRGB::Red);
fill_solid(&leds[20], 20, CRGB::Green);
fill_solid(&leds[40], 20, CRGB::Blue);
FastLED.show();
delay(1000);
}
fill_solid() instead of manual loops for better performanceFastLED.clear() as a shortcut for filling with black (off)CRGB::Red are more readable than CRGB(255, 0, 0)Once you're comfortable with solid colors, move on to Animations to learn how to create dynamic effects.