cookbook/reference/api.md
Difficulty Level: ⭐ All Levels Time to Find Information: 2-5 minutes Prerequisites: None (quick lookup reference)
You'll Find:
Comprehensive reference for FastLED functions and APIs.
// Add LEDs (single pin)
FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS);
// Add LEDs with clock pin (APA102, etc.)
FastLED.addLeds<LED_TYPE, DATA_PIN, CLOCK_PIN, COLOR_ORDER>(leds, NUM_LEDS);
// Set global brightness (0-255)
FastLED.setBrightness(value);
// Set maximum power draw
FastLED.setMaxPowerInVoltsAndMilliamps(volts, milliamps);
// Set dithering mode
FastLED.setDither(BINARY_DITHER); // or DISABLE_DITHER
// Set color correction
FastLED.setCorrection(TypicalLEDStrip); // or TypicalPixelString
// Set color temperature
FastLED.setTemperature(Candle); // or others
FastLED.show(); // Update LEDs
FastLED.clear(); // Set all to black
FastLED.clear(true); // Clear and show
FastLED.delay(ms); // Delay and handle timing
uint16_t fps = FastLED.getFPS(); // Get current frame rate
// Create colors
CRGB color = CRGB(r, g, b); // RGB
CHSV color = CHSV(h, s, v); // HSV
CRGB color = CRGB::Red; // Named colors
// Blend colors
CRGB result = blend(color1, color2, amount);
// Fade colors
color.fadeToBlackBy(amount); // 0-255
color.nscale8(scale); // Scale brightness
// Add colors
leds[i] += CRGB(10, 0, 0); // Add red
fill_solid(leds, NUM_LEDS, color);
fill_rainbow(leds, NUM_LEDS, startHue, deltaHue);
fill_gradient_RGB(leds, NUM_LEDS, color1, color2);
fill_gradient_RGB(leds, NUM_LEDS, color1, color2, color3);
fadeToBlackBy(leds, NUM_LEDS, amount); // Fade toward black
fadeLightBy(leds, NUM_LEDS, amount); // Same as fadeToBlackBy
nscale8(leds, NUM_LEDS, scale); // Scale brightness
blur1d(leds, NUM_LEDS, amount); // Blur 1D array
uint8_t scale8(uint8_t i, uint8_t scale); // i * scale / 255
uint16_t scale16(uint16_t i, uint16_t scale); // 16-bit version
uint8_t map(value, fromLow, fromHigh, toLow, toHigh);
uint8_t qadd8(uint8_t i, uint8_t j); // Add, max 255
uint8_t qsub8(uint8_t i, uint8_t j); // Subtract, min 0
uint8_t sin8(uint8_t theta); // Fast 8-bit sine
uint16_t sin16(uint16_t theta); // 16-bit sine
uint8_t beat8(uint16_t bpm); // Sawtooth
uint8_t beatsin8(uint16_t bpm, uint8_t min, uint8_t max); // Sine wave
uint8_t random8(); // 0-255
uint8_t random8(uint8_t max); // 0 to max-1
uint8_t random8(uint8_t min, uint8_t max);
uint16_t random16(); // 0-65535
uint16_t random16(uint16_t max);
uint8_t inoise8(uint16_t x);
uint8_t inoise8(uint16_t x, uint16_t y);
uint8_t inoise8(uint16_t x, uint16_t y, uint16_t z);
uint16_t inoise16(uint32_t x, uint32_t y, uint32_t z);
EVERY_N_MILLISECONDS(ms) { /* code */ }
EVERY_N_SECONDS(seconds) { /* code */ }
// Get current time
uint32_t now = millis();
RainbowColors_p
RainbowStripeColors_p
CloudColors_p
PartyColors_p
OceanColors_p
LavaColors_p
ForestColors_p
HeatColors_p
// Use palette
CRGB color = ColorFromPalette(palette, index, brightness, blendType);
// blendType: LINEARBLEND or NOBLEND