Go Down

Topic: Simplifying control of LED 2801 square pixel (Read 3 times) previous topic - next topic


Hi there,

As say others, I'm a newbie, and want to create some 'very simple' Arduino code for controlling a strip of LED pixels on a string (of 20), 4 strings connected in total. My project will eventually monitor internet data and convert this into lighting particular LED modules (I'll save the ethernet/server bits for later when I have some development support).

The bit I'd love to work out now is how can I control each LED module in the string of 80 in such a way that I can write something like '1,7,9,25' to light LED number 1, 7, 9, and 25 in the string? Obviously intensity, time, colour, etc are also important but most of the tutorials out there seem to be using more pattern-based code (to create animations for example) rather than a basic identification and control of each module in the string. The variables i would love to control are:
- Which pixel in the string I want to control
- Whether it should be on/off
- For how long it remains on
- Fade in/out duration
- Colour value

I will then look to control multiple LEDs in small groups. E.g. 3-7 LEDs at a time.

Any support or example code would be greatly appreciated so I can start experimenting with it to getting a better grasp. Things such as wiring up the Arduino, LEDs and power supply are already understood.

Many thanks!


You have one of the most used LED drivers to work with, the WS2801 (at least, I believe that's what you're referring to in your subject line.)  Use FastSPI to control the string.  You can leave it as one long string even (even if you cut it into four separate pieces, just connect the ends back together with wires.)

FastSPI keeps an array of the string:

NUM_LEDS = 20;
// there are some other needed lines here, but for this post they're irrelevant - get them from the FastSPI "testled" sketch.

leds[px].r = xxx;
leds[px].g = xxx;
leds[px].b = xxx;

Each 'px' refers to a specific pixel.  So in your case, you'd want px = 0, 6, 8, and 24 - remember it always starts counting from 0 on, not 1.

FastSPI does work with the SPI port, so if you have other SPI devices, keep in mind that the 2801's don't have an ENable pin.

Your other option is to bit-bang your way there, which I've done also in similar fashion: keep an array of the led count, then address each LED by it's array index.


KirAsh4 - thanks very much!

I had just downloaded the FastSPI ZIP when i read your response. Your input still really helps though - particularly addressing specific LEDs as I hadn't worked that bit out.

I'll try implementing this and see how far I get.

Much appreciated.


No problem.  Let us know if you run into issues or have more questions.


Hi KirAsh4,

If I may ask another question or two...

So I've had a go at putting the basic code together for a predefined set of LEDs to switch on, as per your suggestions... i hope.

I'm trying to figure out how to 'group' a set of LEDs so that I can control, for example, 5 modules at once. Is it an array that I need to create? Such as this:

LED led[group name] = {LED(2), LED(20), LED(47), LED(60)};

Essentially, where I'm heading for is that these 4 LEDs light up in blue, whilst all unspecified LEDs remain white, for example. And then another set of LEDs light up in blue, and the remaining 75 go white. All dependent upon the XML data feed from elsewhere (that bits for later).

I appreciate there must be ws2801 snippets/examples out there that I can find to build around - I will continue to hunt for them - but no success yet, most likely due to my level of understanding. Any pointers or examples very much appreciated.

Thanks again,


P.S. This is the code I have put together so far:

#include <FastSPI_LED.h>

#define NUM_LEDS 80

// Sometimes chipsets wire in a backwards sort of way
struct CRGB { unsigned char b; unsigned char r; unsigned char g; };
// struct CRGB { unsigned char r; unsigned char g; unsigned char b; };
struct CRGB *leds;

#define PIN 4

void setup()

  leds = (struct CRGB*)FastSPI_LED.getRGBData();

void loop() {
//work out how to switch on/off groups - HIGH/LOW?,
//how to group different sets of LEDs - arrays?
//how to control the other 76 LEDs as one group as simply as possible
//how to fade in/out

leds[2].r = 255;
leds[2].g = 255;
leds[2].b = 255;
leds[20].r = 255;
leds[20].g = 255;
leds[20].b = 255;
leds[47].r = 255;
leds[47].g = 255;
leds[47].b = 255;
leds[60].r = 255;
leds[60].g = 255;
leds[60].b = 255;

Go Up