CNAP
03 / Templates · intermediate

NEOPIXEL MATRIX RAINBOW

Open in Playground

8×8 WS2812B NeoPixel matrix running a diagonal rainbow wave. Each pixel is addressed by row and column via Adafruit NeoPixel.

intermediateNeoPixelWS2812BmatrixRGBanimation
Circuit
Code
sketch.inoArduino C++
28 lines
// NeoPixel Matrix 8×8 — diagonal rainbow wave
#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);
}
Components
  • Arduino Uno
    01
  • NeoPixel Matrix 8×8 (wokwi-neopixel-matrix)
    02
Wiring
Component PinArduino Pin
VCC5V
GNDGND
DIN (Data In)Pin 6