Adafruit Neopixel shield examples

In this article we take a look at the Neopixel shield, as you have probably guessed this is an Arduino shield which is basically 5 rows of 8 Neopixel RGB LEDs. Using a couple of Adafruit libraries we have various code examples for you to try

This is what the shield looks like

Code

You need the Adafruit Neopixel and Neomatrix libraries for the last example. These can be installed via the library manager

Example 1

This is the default example

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define LED_NUM 40
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_NUM, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
leds.begin(); // This initializes the NeoPixel library.
}
void loop()
{
led_set(10, 0, 0);//red
led_set(0, 0, 0);
led_set(0, 10, 0);//green
led_set(0, 0, 0);
led_set(0, 0, 10);//blue
led_set(0, 0, 0);
}
void led_set(int R, int G, int B)
{
for (int i = 0; i < LED_NUM; i++)
{
leds.setPixelColor(i, leds.Color(R, G, B));
leds.show();
delay(50);
}
}

Example 2

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define LED_NUM 40
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_NUM, PIN, NEO_GRB + NEO_KHZ800);
void setup()
{
leds.begin(); // This initializes the NeoPixel library.
}
void led_set(int R, int G, int B)
{
for (int i = 0; i < LED_NUM; i++)
{
leds.setPixelColor(i, leds.Color(R, G, B));
leds.show();
//delay(50);
}
}
void loop()
{
led_set(10, 0, 0);//red
delay(1500);
led_set(0, 0, 0);
delay(1500);
led_set(0, 10, 0);//green
delay(1500);
led_set(0, 0, 0);
delay(1500);
led_set(0, 0, 10);//blue
delay(1500);
led_set(0, 0, 0);
delay(1500);
}

Example 3

//random red LED
#include <Adafruit_NeoPixel.h>
#define PIN 6
#define LED_NUM 40
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_NUM, PIN, NEO_GRB + NEO_KHZ800);
int rndLed;
void setup()
{
leds.begin(); // This initializes the NeoPixel library.
randomSeed(analogRead(0));
}
void loop()
{
rndLed = random(0, 7);
leds.setPixelColor(rndLed, leds.Color(5, 0, 0));
leds.show();
delay(500);
leds.setPixelColor(rndLed, leds.Color(0, 0, 0));
leds.show();
}

Example 4

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define LED_NUM 40
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_NUM, PIN, NEO_GRB + NEO_KHZ800);
int rndLed;
int rndRed;
int rndGreen;
int rndBlue;
void setup()
{
leds.begin(); // This initializes the NeoPixel library.
randomSeed(analogRead(0));
}
void loop()
{
rndLed = random(0, 7);
rndRed = random(0, 7);
rndGreen = random(0, 7);
rndBlue = random(0, 7);
leds.setPixelColor(rndLed, leds.Color(rndRed, rndGreen, rndBlue));
leds.show();
delay(250);
leds.setPixelColor(rndLed, leds.Color(0, 0, 0));
leds.show();
}

Example 5

#include <Adafruit_NeoPixel.h>
#define PIN 6
#define LED_NUM 40
Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_NUM, PIN, NEO_GRB + NEO_KHZ800);
int rndLed;
int rndRed;
int rndGreen;
int rndBlue;
void setup()
{
leds.begin(); // This initializes the NeoPixel library.
randomSeed(analogRead(0));
}
void loop()
{
rndLed = random(0, 7);
rndRed = random(0, 7);
rndGreen = random(0, 7);
rndBlue = random(0, 7);
leds.setPixelColor(rndLed, leds.Color(rndRed, rndGreen, rndBlue));
leds.show();
delay(250);
}

 

Example 6 

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#ifndef PSTR
 #define PSTR // Make Arduino Due happy
#endif
 
#define PIN 6
 
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(5, 8, PIN,
  NEO_MATRIX_TOP     + NEO_MATRIX_RIGHT +
  NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
  NEO_GRB            + NEO_KHZ800);
 
const uint16_t colors[] = {
  matrix.Color(150, 0, 0), matrix.Color(0, 150, 0), matrix.Color(0, 0, 150) };
 
void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(40);
  matrix.setTextColor(colors[0]);
}
 
int x    = matrix.width();
int pass = 0;
 
void loop() {
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  matrix.print(F("Howdy"));
  if(--x < -36) {
    x = matrix.width();
    if(++pass >= 3) pass = 0;
    matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(100);
}

 

Video

Here is a video of the examples above in action