This is an old revision of the document!


Shades and Colors

You can fully control the RGB LED and make it shine any color you wish in full 24-bit glory by playing with the intensity of the shades of Red, Green and Blue. You will need to use the analogWrite() function instead.

int greenLED = 11;     //green LED on Arduino pin 11           
int redLED = 8;        //red LED on pin 8
int blueLED = 10;      //blue LED on pin 10 
 
void setup()                    // run once, when the sketch starts
{
  pinMode(greenLED, OUTPUT);      // sets the digital pin as output
  pinMode(redLED, OUTPUT);
  pinMode(blueLED, OUTPUT);
}
 
// controls the RGB LED
void color(unsigned char red, unsigned char green, unsigned char blue)
{
  analogWrite(redLED, 255-red);
  analogWrite(greenLED, 255-green);
  analogWrite(blueLED, 255-blue);
}
 
void loop()                     // run over and over again
{
  unsigned char color_rgb[3];
 
  // Start off with red.
  color_rgb[0] = 255;
  color_rgb[1] = 0;
  color_rgb[2] = 0;  
 
  // Choose the colours to increment and decrement.
  for (int decColour = 0; decColour < 3; decColour += 1) {
    int incColour = decColour == 2 ? 0 : decColour + 1;
 
    // cross-fade the two colours.
    for(int i = 0; i < 255; i += 1) {
      color_rgb[decColour] -= 1;
      color_rgb[incColour] += 1;
 
      color(color_rgb[0], color_rgb[1], color_rgb[2]);
      delay(15);
}}}

You can make the LED display any color, but you will need to use analogWrite()

Fig. 1: The RGB LED on the Sparrow Node

LED uC PIN Arduino Pin
R PB4 8
G PB5 11
B PB6 10
Tab. 1: Led pinout