Class: Adafruit_NeoPixel(NeoPixels, Pin, LED Type)

Note: This page is still a work in progress.

The Adafruit_NeoPixel() class comprises an object constructor and several methods that provide control over NeoPixel color, brightness, and initialization.

Requirements:

The Adafruit_NeoPixel.h header file must be included in any sketch using this functionality.

#include <Adafruit_NeoPixel.h>

.

.

void setup(){

your setup code;

}

Adafruit_NeoPixel()

The Adafruit_NeoPixel() object defines the basic attributes of the NeoPixel element. Once an instance has been instantiated, it can be used to control the behavior of the strip.

Return: Adafruit_NeoPixel object.

Argument Type Description
NeoPixels 16 bit unsigned integer The number of NeoPixels in a strip. The first pixel is numbered 0, the last pixel is the total number of pixels - 1.For example, if the strip contains 60 NeoPixels, the first is numbered 0 and the last is numbered 59.
Pin 8 bit unsigned integer This is the output pin on the Arduino device (Uno, Mega, Flora, etc.) to which the bit stream is sent.
LED Type

8 bit unsigned integer

This defines the type of LED:

  • 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)

Constructor

Adafruit_NeoPixel(uint16_t NeoPixels, uint8_t Pin, uint8_t LEDType LEDType);

The following example defines a Adafruit_NeoPixel object the has 60 LEDs where the data is sourced from pin 6 of the Arduino device, and the LED

Example:

#define PIN = 6;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

Methods

begin()

begin()

Initializes the pixel or pixel stip and sets the LEDs to an off state. The begin() method has no arguments.

Return: void

The following example defines an Adafruit_NeoPixel object and intitializes it.

Example:

#define PIN = 6;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

.

.

strip.begin();

 

void setup(){

//setup calls;

}

void loop(){

//calls to procedures

}

getBrightness()

getBrightness()

Gets the brightness of the neoPixel.

Return: 8-bit unsigned integer representing the brightness of the pixel.

The following example gets the brightness value for the NeoPixel object and saves it in a variable.

Example:

#define PIN = 6;

Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

strip1.begin();

uint8_t brightness;

 

void setup(){

//setup calls;

}

void loop(){

brightness = strip1.getBrightness();

delay(1000);

}

getPixels()

getPixels()

Returns pointer to pixels[] array. Pixel data is stored in device-native format and is not translated here. Application will need to be aware whether pixels are RGB vs. GRB and handle colors appropriately.

Return: 8-bit unsigned integer pointer value

The following example gets the pixel array pointer and saves it in a pointer variable.

Note: the structure and contents of the pixel array are discussed in a separate document.

Example:

#define PIN = 6;

Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);

strip1.begin();

uint8_t brightness;

*uint8_t pixels;

 

void setup(){

//setup calls;

}

void loop(){

brightness = strip1.getBrightness();

pixels = strip1.getPixels();

delay(1000);

}

 

getPixelColor()

getPixelColor()

getPixelColor() Queries thecolor from a previously-set pixel.

Return: packed 32-bit (uint32_t) RGB Value

Argument Type Description
n 16 bit unsigned integer Returns a packed 32-bit RBG value from a previously set pixel. Returns 0 if n is out of bounds (n > number of pixels).

The following example demonstrates the use of getPixelColor() to get the color of one pixel and then incrementally set the remaining NeoPixels to that color.

Example:

#define PIN = 6;

#define NUMPIXELS = 60;

uint16_t color;

 

Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);

strip1.begin();

 

void setup(){

strip1.setPixelColor(0, 255,0, 0) // set color of first pixel to red

}

void loop(){

for (int i = 0; i<NUMPIXELS-1; i++){

color= strip1.getPixelColor(i);

strip1.setPixelColor(i, color);

strip1.show();

delay(500);

}//end for

 

}

 

 

show()

setBrightness()

setPin()

setPixelColor()