CNAP

NeoPixel Matrix Reference

A grid of WS2812B addressable RGB LEDs, driven over a single data line and chainable via DOUT.

Pin names

NameDescription
GNDGround
VCCPower (5V)
DINData In — connect to a GPIO pin
DOUTData Out — chain to the next matrix/strip's DIN

Attributes

NameDescriptionDefault
rowsNumber of rows in the grid"8"
colsNumber of columns in the grid"8"

Usage

Connect VCC to 5V, GND to GND, and DIN to a GPIO pin. Address pixels with the Adafruit NeoPixel library, indexing them row-major (row * COLS + col).

#include <Adafruit_NeoPixel.h>

#define DATA_PIN   6
#define ROWS       8
#define COLS       8
#define NUMPIXELS  (ROWS * COLS)

Adafruit_NeoPixel matrix(NUMPIXELS, DATA_PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  matrix.begin();
  matrix.setBrightness(60);
}

void loop() {
  static uint16_t offset = 0;
  for (int row = 0; row < ROWS; row++) {
    for (int col = 0; col < COLS; col++) {
      uint16_t hue = offset + (uint16_t)(row + col) * 4096;
      uint32_t color = matrix.gamma32(matrix.ColorHSV(hue, 255, 200));
      matrix.setPixelColor(row * COLS + col, color);
    }
  }
  matrix.show();
  offset += 512;
  delay(30);
}

Examples

DescriptionAttrs
Default 8×8 grid{}
16×16 grid{ "rows": "16", "cols": "16" }

See also

  • NeoPixel — single pixel using the same WS2812B protocol
  • LED Ring — NeoPixels arranged in a ring instead of a grid