Datasheet

Arduino Library Use
It’s assumed at this point that you have the Adafruit_NeoPixel library for Arduino installed and have run the
strandtest example sketch successfully. If not, return to the prior page for directions to set that up.
To learn about writing your own NeoPixel sketches, let’s begin by dissecting the strandtest sketch
All NeoPixel sketches begin by including the header file:
The block of code that follows is mostly descriptive comments. Only the last line is really doing any work:
The first line assigns a number to the symbol “PIN” for later reference. It doesn’t
need
to be done this way, but makes it
easier to change the pin where the NeoPixels are connected without digging deeper into the code.
The last line declares a NeoPixel
object.
We’ll refer to this by name later to control the strip of pixels. There are three
parameters or
arguments
in parenthesis:
1. The number of sequential NeoPixels in the strip. In the example this is set to 60, equal to 1 meter of medium-
density strip. Change this to match the actual number you’re using.
2. The pin number to which the NeoPixel strip (or other device) is connected. Normally this would be a number, but
we previously declared the symbol PIN to refer to it by name here.
3. A value indicating the type of NeoPixels that are connected. In most cases you can leave this off and pass just
two arguments; the example code is just being extra descriptive. If you have a supply of classic “V1” Flora pixels,
those require NEO_KHZ400 + NEO_RGB to be passed here.
Then, in the setup() function, call begin() to prepare the data pin for NeoPixel output:
The second line, strip.show(), isn’t absolutely necessary, it’s just there to be thorough. That function pushes data out to
the pixels…since no colors have been set yet, this initializes all the NeoPixels to an initial “off” state in case some were
#include <Adafruit_NeoPixel.h>
#define PIN 6
// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
// NEO_KHZ800 800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
// NEO_KHZ400 400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
// NEO_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
// NEO_RGB Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
For through-hole 8mm NeoPixels, use NEO_RGB instead of NEO_GRB in the strip declaration. For RGBW
LEDs use NEO_RGBW (some RGBW strips use NEO_GRBW, so try that if you're getting unexpected results!)
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
© Adafruit Industries https://learn.adafruit.com/adafruit-neopixel-uberguide Page 43 of 68