Arduino Example Snippet
#include <Adafruit_NeoPixel.h>
#define DATA_PIN 14
#define NUM_LEDS 64
#define BRIGHTNESS 30
Adafruit_NeoPixel strip(NUM_LEDS, 14, NEO_GRB + NEO_KHZ800);
// Serpentine XY mapping for 8x8 grid
uint8_t XY(uint8_t x, uint8_t y) {
if (y & 1) return y * 8 + (7 - x);
return y * 8 + x;
}
void setup() {
Serial.begin(115200);
Serial.println("8x8 Display Demo Starting...");
strip.begin();
strip.setBrightness(BRIGHTNESS);
strip.clear();
strip.show();
}
void loop() {
// Pattern 1: Color wipe
colorWipe(strip.Color(255, 0, 0), 50); // Red
colorWipe(strip.Color(0, 255, 0), 50); // Green
colorWipe(strip.Color(0, 0, 255), 50); // Blue
// Pattern 2: Rainbow cycle
rainbowCycle(3);
// Pattern 3: Bouncing pixel
bouncingPixel(80);
}
// Fill display one pixel at a time
void colorWipe(uint32_t color, int wait) {
for(int y = 0; y < 8; y++) {
for(int x = 0; x < 8; x++) {
strip.setPixelColor(XY(x, y), color);
strip.show();
delay(wait);
}
}
}
// Rainbow effect that cycles through all pixels
void rainbowCycle(int cycles) {
for(int cycle = 0; cycle < cycles; cycle++) {
for(int j = 0; j < 256; j++) {
for(int y = 0; y < 8; y++) {
for(int x = 0; x < 8; x++) {
int pixelHue = ((y * 8 + x) * 65536L / NUM_LEDS + j * 256) % 65536;
strip.setPixelColor(XY(x, y), strip.gamma32(strip.ColorHSV(pixelHue)));
}
}
strip.show();
delay(20);
}
}
}
// Single pixel bouncing around
void bouncingPixel(int frames) {
int x = 0, y = 0;
int dx = 1, dy = 1;
for(int i = 0; i < frames; i++) {
strip.clear();
// Draw trail (fading previous position)
for(int ty = 0; ty < 8; ty++) {
for(int tx = 0; tx < 8; tx++) {
uint32_t c = strip.getPixelColor(XY(tx, ty));
if(c != 0) {
// Fade out
uint8_t r = (c >> 16) & 0xFF;
uint8_t g = (c >> 8) & 0xFF;
uint8_t b = c & 0xFF;
strip.setPixelColor(XY(tx, ty), strip.Color(r/2, g/2, b/2));
}
}
}
// Draw bouncing pixel
strip.setPixelColor(XY(x, y), strip.Color(255, 255, 255));
strip.show();
// Update position
x += dx;
y += dy;
// Bounce off edges
if(x <= 0 || x >= 7) dx = -dx;
if(y <= 0 || y >= 7) dy = -dy;
// Keep in bounds
x = constrain(x, 0, 7);
y = constrain(y, 0, 7);
delay(50);
}
}