RedBoard Turbo Hookup Guide

Pages
Contributors: Alex the Giant
Favorited Favorite 2

Example: Addressable RGB LED

In this last example, we'll take a look at how to use the RGB LED on the RedBoard Turbo. The RGB LED comes in the form of a WS2812, which could be great as a status LED or for debugging if you don't want or need to use serial terminal. In the example below, we'll test the functionality of the LED by using the rainbow fade code below. To use this code, you will need to install the NeoPixel library. You can obtain these libraries through the Arduino Library Manager. Search for NeoPixel and you should be able to install the latest version. If you prefer downloading the libraries manually you can grab them from the GitHub repository:

Once the library has been installed, copy and paste the following code into your Arduino IDE.

language:c
#include <Adafruit_NeoPixel.h>
#define LEDPIN RGB_LED // connect the Data from the strip to this pin on the Arduino
#define NUMBER_PIEXELS 1 // the number of pixels in your LED strip
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMBER_PIEXELS, LEDPIN, NEO_GRB + NEO_KHZ800);

int wait = 10; // how long we wait on each color (milliseconds)

void setup() {
  strip.begin();
}

void loop() {

    for (int color=0; color<255; color++) {
      for (int i=0; i<strip.numPixels(); i++) {
        strip.setPixelColor(i, Wheel(color));
       }
    strip.show();
    delay(wait);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
   return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else if(WheelPos < 170) {
    WheelPos -= 85;
   return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  }
}

Once uploaded, you should see the LED changing colors. Notice in the code, the RGB LED's pin is defined using RGB_LED. You could also call it using LED4 or it's pin number, 44.

Controlling RGB LED