Hello, how do I get the Pixel color of an LED with FastLED?

(Celestale) #1

Hello, how do I get the Pixel color of an LED with FastLED?

(Mark Kriegsman) #2

The pixels are just an array, and you can access it directly:

CRGB color;

color = leds[ i ];

There’s no function call required.

(Mark Kriegsman) #3

Let us know if you want any help and welcome!

(Scottie D369) #4

Here’s how you define the color just pull up a patlette chart to choose a color. the 3 #'s in ()


(Scottie D369) #5

Here’s my FADE code here >>>

Put together & tested by:
Scottie Digital
#include “FastLED.h”
#define NUM_LEDS 288 // # of LEDS in the strip
#define PIN 8 // Output Pin to Data Line on Strip
#define COLOR_ORDER GRB // I had to change this for my strip if your color is off then you know.
int fadeAmount = 5; // Set the amount to fade I usually do 5, 10, 15, 20, 25 etc even up to 255.
int brightness = 0;

void setup()
FastLED.addLeds<WS2812B, PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );

void loop()
for(int i = 0; i < NUM_LEDS; i++ )
leds[i].setRGB(0,255,250); // Set Color HERE!!!
brightness = brightness + fadeAmount;
// reverse the direction of the fading at the ends of the fade:
if(brightness == 0 || brightness == 255)
fadeAmount = -fadeAmount ;
delay(9); // This delay sets speed of the fade. I usually do from 5-75 but you can always go higher.

(Mark Kriegsman) #6

I think the original question was how to get the color of a pixel, but if it was how to set the color of a pixel, there are a few ways to do it. Me, I usually just write an assignment statement instead of setRGB:

leds[i] = CRGB( 0, 255, 250);
leds[i] = CRGB::Aqua;

This way I can also switch it to use HSV colors just as easily:

leds[i] = CHSV( hue, 255, 255);

There’s documentation on the wiki here, too: https://github.com/FastLED/FastLED/wiki/Pixel-reference

(Celestale) #7

Hello, thanks Scottie and Mark for your replies.

I’m currently using a APA102 LED strip on a small ferris wheel model. Could I get some suggestions/sample codes on what types of interesting LED patterns to use?

Now I already have the following patterns:
all solid colors

(Celestale) #8

How can I modify this Cylon code to make it work without delay(speed)? Because I’m multi-tasking my Arduino Uno, I can’t use any delay()

void cylon(CRGB c, int width, int speed) {
for (int i = 0; i <= NUM_LEDS - width; i++) {
for (int j = 0; j < width; j++) {
leds[i + j] = c;


  for (int j = 0; j < 5; j++) {
    leds[i + j] = CRGB::Black;


for (int i = NUM_LEDS - width; i >= 0; i–) {
for (int j = 0; j < width; j++) {
leds[i + j] = c;
for (int j = 0; j < width; j++) {
leds[i + j] = CRGB::Black;

(Mark Kriegsman) #9

Check out the “DemoReel100” code, in particular the little function called “Sinelon”. https://github.com/FastLED/FastLED/blob/master/examples/DemoReel100/DemoReel100.ino

It basically just says:

void sinelon()
// a colored dot sweeping back and forth, with fading trails
fadeToBlackBy( leds, NUM_LEDS, 20);
int pos = beatsin16(13,0,NUM_LEDS);
leds[pos] += CHSV( gHue, 255, 192);

As for other thoughts on multi-tasking, you might also get some ideas from “TwoAnimationsAtTheSameTime” here https://plus.google.com/112916219338292742137/posts/FjfHnDP5tPK

(Celestale) #10


How do I change the speed of “Sinelon”?

I tried to change the values in

int pos = beatsin16(13,0,NUM_LEDS)

it seems to change the length of the “Sinelon” and the speed. Is this the right way?

(Mark Kriegsman) #11

The first argument to the beat function is the number of repeats per minute.

To change the fade speed, play with the argument to fadeToBlackBy.

That help?