ShiftBrite Shield – A color mixer for Arduino

8 07 2010

LEDs… The beauty of electronics, the soul of a project. What can I say, I love LEDs!! Each time I see a project involving RGB LEDs, several ideas come to my mind and I’ve always wondered I had a good hardware platform to mess around with them!

So, after some days surfing through datasheets, online shops and tech documents, I reached one conclusion: Controlling several High-intensity RGB LEDs IS DIFFICULT. You need to supply the correct voltage to each one of the LEDs (without using resistors: when you are dealing with a 3A current, each tiny resistor can dissipate more energy in heat that your LED does, what is not very efficient…), you need a very good heatsink and an amplifier stage to control them using your Arduino. Dealing with these handicaps can be very though, or it can be just expensive. Guess which is the option that I chose…

MegaBrite, from Macetech Industries

This tiny piece of hardware simplifies a LOT your life if you want to make some microcontroller-driven illumination project. It is composed by three high-intensity LEDs (Actually inside each one of the encapsulations there are 5 small dyes, totalling 15 x 20mA LEDs = 300mA of pure colour in each MegaBrite). But the cool thing about this component is that each MegaBrite has an Allegro A6281 chip that does all the hard work in your project if you want to light a huge strip of RGB LEDs. You can find more about ShiftBrites and MegaBrites at Macetech, but roughly they work like this: Your microcontroller passes an binary word containing the values you want for each R, G and B LED to the first MegaBrite. Then, toggling one pin you can shift this information to the next MegaBrite of your strip, and so on, setting each one of the LEDs the colour you want. Easy enough for me!!

I ordered 5 MegaBrites from the Macetech online store for 10$ each one (yes, this hobby is expensive, and more if you are a beginner in electronics like me…) and then I was ready to start the interesting thing.

Making them to work with Arduino was as easy as looking for the libraries at Macetech, and after modifying some examples, I was confident enough to start doing some maths. The problem that appears when using any RGB space (yes, the color space is an R³ space, like points in space) is that it is not human-friendly: If you want to change frome a bright blue (ie R86 G30 B229) to a darker one (R50 G14 B140) you have to change all RGB coordinates, what is not very intuitive. In order to solve this problem, some decades ago the HSV space was developed. In it, the RGB coordinates are transformed into a kind of distorted polar coordinates, where you can determine a colour by its Hue (tone), Saturation (more or less colourful) and Value (brightness). This is quiiite more human-friendly, and it is widely used in colour pickers for computer graphic programs as GIMP.

Which is the next step? Of course, creating a real-world color mixer for interfacing ShiftBrite LEDs with Arduino in an easy way!

So, as I really avoid as far as possible using the protoboard (wires messing around, false contacts, noise, fragility…), soon I was designing a PCB in Eagle (I have to say that I have installed Kicad, an open-source alternative for creating PCBs, but I’m too lazy to learn how to use it now, although sooner or later I will try to use it).

I decided to create this board without going to the electronic components shop, using only recycled components that I’ve savaged from different sources. This means that I had to create my own library for Eagle, what is really easy following the Sparkfun’s tutorial.

At the end, this is what I achieved:

· Schematic

· Board

And the Arduino code:

#define clockpin 13 // CI
#define enablepin 10 // EI
#define latchpin 9 // LI
#define datapin 11 // DI

#define NumLEDs 1

void hsv2rgb(float h, float s, float v, int &R, int &G, int &B);
void SB_SendPacket();
void WriteLEDArray();

int LEDChannels[NumLEDs][3] = {
int SB_CommandMode;
int SB_RedCommand;
int SB_GreenCommand;
int SB_BlueCommand;
float hue, sat, val;
int R, G, B;

void setup() {

  pinMode(datapin, OUTPUT);
  pinMode(latchpin, OUTPUT);
  pinMode(enablepin, OUTPUT);
  pinMode(clockpin, OUTPUT);
  SPCR = (1<<<<digitalWrite(latchpin, LOW);
  digitalWrite(enablepin, LOW);

void loop() {

  hue = (analogRead(0)/1024.0);
  sat = (analogRead(1)/1024.0);
  val = (1-analogRead(2)/1024.0);

  //sat = 1 - (0.58198*(exp(sat*sat)-1));    // This transformation intends to make saturation more linear, although it doesn't seem to really work


  hsv2rgb(hue, sat, val, R, G, B);

  R = R*4;
  G = G*4;
  B = B*4;

  LEDChannels[0][0] = R;
  LEDChannels[0][1] = G;
  LEDChannels[0][2] = B;



void SB_SendPacket() {

  if (SB_CommandMode == B01) {
    SB_RedCommand = 120;
    SB_GreenCommand = 100;
    SB_BlueCommand = 100;

  SPDR = SB_CommandMode << 6 | SB_BlueCommand>>4;
  while(!(SPSR & (1<>6;
  while(!(SPSR & (1<>8;
  while(!(SPSR & (1<while(!(SPSR & (1<void WriteLEDArray() {

  SB_CommandMode = B00; // Write to PWM control registers
  for (int h = 0;hdelayMicroseconds(15);
  digitalWrite(latchpin,HIGH); // latch data into registers

  SB_CommandMode = B01; // Write to current control registers
  for (int z = 0; z < NumLEDs; z++) SB_SendPacket();
  digitalWrite(latchpin,HIGH); // latch data into registers


void hsv2rgb(float H, float V, float S, int& R, int& G, int& B) {

  int var_i;
  float var_1, var_2, var_3, var_h, var_r, var_g, var_b;

  /*if ( S == 0 )                       //HSV values = 0 ÷ 1
     R = V * 255;
     G = V * 255;
     B = V * 255;

  var_h = H * 6;
  if ( var_h == 6 ) var_h = 0;      //H must be < 1
  var_i = int( var_h ) ;            //Or ... var_i = floor( var_h )
  var_1 = V * ( 1 - S );
  var_2 = V * ( 1 - S * ( var_h - var_i ) );
  var_3 = V * ( 1 - S * ( 1 - ( var_h - var_i ) ) );

  if      ( var_i == 0 ) {
    var_r = V     ;
    var_g = var_3 ;
    var_b = var_1 ;
  else if ( var_i == 1 ) {
    var_r = var_2 ;
    var_g = V     ;
    var_b = var_1 ;
  else if ( var_i == 2 ) {
    var_r = var_1 ;
    var_g = V     ;
    var_b = var_3 ;
  else if ( var_i == 3 ) {
    var_r = var_1 ;
    var_g = var_2 ;
    var_b = V     ;
  else if ( var_i == 4 ) {
    var_r = var_3 ;
    var_g = var_1 ;
    var_b = V     ;
  else                   {
    var_r = V     ;
    var_g = var_1 ;
    var_b = var_2 ;

  R = (1-var_r) * 255;                  //RGB results = 0 ÷ 255
  G = (1-var_g) * 255;
  B = (1-var_b) * 255;

Videos soon!!!
(Here I don’t have enough 3G signal to upload them!)

I’ve been published in PCB Heaven!! Thanks very much for your attention!




12 responses

8 07 2010


Nice work, it will be featured in pcbheaven site under Hacks ‘n Mods page


(please delete after read)

9 07 2010

Muy interesante. Yo ando trasteando con shiftbrites y arduinos también, y tarde o temprano haré algo para controlar manualmente el rgb. Puedes verlo en Por cierto, el tío de macetech ha tuiteado tú proyecto, así te he encontrado. Un saludo.

9 07 2010

Jaja, gracias Juan, ya decía yo que había demasiadas visitas al blog, no sabía lo del twitter!!
A ver si me animo a hacer un vídeo en condiciones y a subirlo a Youtube.
Actualizo ahora que he visto tu página:
Madre mía, un proyecto muuuy currado, que se acerca bastante a arte… Muy muy interesante, creo que sacaré bastantes ideas de él, que estoy falto de algoritmos de control de LEDs. Gracias!

9 07 2010

Pues nada, píllate el codigo – busca britable en Google code – y si le puedes sacar partido, o se te ocurre alguna mejora, pues estupendo.

16 10 2012
classes for real estate license

This paragraph is really a fastidious one it assists new net people, who are wishing in favor of blogging.

16 12 2012

This design is wicked! You obviously know how to keep a reader entertained.
Between your wit and your videos, I was almost moved
to start my own blog (well, almost…HaHa!
) Excellent job. I really enjoyed what you had to say,
and more than that, how you presented it.
Too cool!

20 01 2013

I do not know if it’s just me or if everybody else encountering issues with your blog. It looks like some of the written text within your content are running off the screen. Can somebody else please provide feedback and let me know if this is happening to them as well? This might be a problem with my browser because I’ve had this happen previously.
Thank you

1 05 2013

Hello, i read your blog from time to time and i own
a similar one and i was just wondering if you get a
lot of spam remarks? If so how do you prevent it, any
plugin or anything you can recommend? I get so much lately it’s driving me crazy so any support is very much appreciated.

17 05 2013

Hi Dear, are you really visiting this website on a regular basis, if so after that you will absolutely obtain nice knowledge.

23 05 2013

We’re a gaggle of volunteers and starting a new scheme in our community. Your web site provided us with useful info to work on. You have done a formidable process and our whole neighborhood might be thankful to you.

5 06 2013

Hey There. I found your weblog the usage of msn.
That is an extremely smartly written article.
I will be sure to bookmark it and return to learn more of your
useful info. Thank you for the post. I’ll certainly comeback.

19 03 2018

es buenisimo el libro lo he empezado después de leerme una traducción de Horus de apolo.


Introduce tus datos o haz clic en un icono para iniciar sesión:

Logo de

Estás comentando usando tu cuenta de Cerrar sesión /  Cambiar )

Google photo

Estás comentando usando tu cuenta de Google. Cerrar sesión /  Cambiar )

Imagen de Twitter

Estás comentando usando tu cuenta de Twitter. Cerrar sesión /  Cambiar )

Foto de Facebook

Estás comentando usando tu cuenta de Facebook. Cerrar sesión /  Cambiar )

Conectando a %s

A %d blogueros les gusta esto: