Installing the NeoPixel Library 

Before copying and pasting the code, you'll need to install the NeoPixel Library. This is much easier than the installation of the IR Library - you can install the NeoPixel library directly from the IDE!

In Arduino, go to Sketch > Include Library > Manage Libraries.

In the library manager, search for NeoPixel

Then, find the latest version (1.1.1 at time of writing) and click install

Once the status bar is finished, restart the Arduino IDE. The NeoPixel library has been installed. 

Code

Copy/Paste the code below. Then, compile and upload it to your metro

You should see your Metro's NeoPixels light up red, white, and blue. 

/*
 * (CIRC18) Metro Express NeoPixel 
 * this circuit was designed for use with the Metro Explorers Guide on Learn.Adafruit.com
 * 
 * note: this code does NOT run on the Metro, only the Metro EXPRESS. 
 * 
 * by Brent Rubell for Adafruit Industries.
 */

// Include the Adafruit Neopixel Library 
#include <Adafruit_NeoPixel.h>

// The default pin for the NeoPixel on the Metro Express is Pin #40
#define METROPIXELPIN            40

// metroPixel takes in both the number of pixels (1, the built-in) and the pin)
Adafruit_NeoPixel metroPixel = Adafruit_NeoPixel(1, METROPIXELPIN);

/* Colors */ 
// note: the max. of colors in these arrays is 220 instead of 255 (super-bright!!)
const int RED[ ] = {155, 0, 0};
const int WHITE[ ] = {155, 155, 155};
const int BLUE[ ] = {0, 0, 255};
const int BLACK [ ] = {0, 0, 0};

void setup() {
  // init. the NeoPixel library 
  metroPixel.begin(); 
}

void loop() {
  // display red on the Metro Express neopixel
  pixelWrite(RED);
  delay(1000);
  // display white on the Metro Express neopixel
  pixelWrite(WHITE);
  delay(1000);
  // display blue on the Metro Express neopixel
  pixelWrite(BLUE);
  delay(1000);
  
  // Sparkle the Neopixel 
  // pixelSparkle();
}

// takes in a pre-defined color (integer array) and sets the pixel to that color
void pixelWrite(const int* color) { 
  metroPixel.setPixelColor(0, metroPixel.Color(color[0],color[1],color[2]));
  // write the pixel color to the Metro's Neopixel
  metroPixel.show(); 

}

// flashes the neopixel on and off rapidly 
void pixelSparkle() { 
  for(int i = 0; i < 5; i++) {
    pixelWrite(BLACK);
    delay(50);
    pixelWrite(WHITE);
    delay(50);
  }
}











Having trouble?

My Code Wont Compile

Make sure that the NeoPixel library was correctly installed to the right location. 

I don't see a NeoPixel on my board.

You must have a Metro, not a Metro Express. This circuit only works with the Metro Express.

This guide was first published on Aug 18, 2017. It was last updated on Aug 18, 2017.

This page (Code) was last updated on Nov 07, 2020.