#include <Adafruit_NeoPixel.h>
#define MATRIX_PIN 2
#define ROWS 8
#define COLS 8
#define NUM_PIXELS (ROWS * COLS)
Adafruit_NeoPixel matrix(NUM_PIXELS, MATRIX_PIN, NEO_GRB + NEO_KHZ800);
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if (WheelPos < 85) {
return matrix.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else if (WheelPos < 170) {
WheelPos -= 85;
return matrix.Color(0, WheelPos * 3, 255 - WheelPos * 3);
} else {
WheelPos -= 170;
return matrix.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
}
void setup() {
matrix.begin();
matrix.setBrightness(50);
matrix.show();
}
void loop() {
static uint16_t offset = 0;
for (int row = 0; row < ROWS; row++) {
for (int col = 0; col < COLS; col++) {
int pixel = row * COLS + col;
// Spread rainbow across rows and columns
byte colorIndex = ((row + col) * 256 / (ROWS + COLS) + offset) & 255;
matrix.setPixelColor(pixel, Wheel(colorIndex));
}
}
matrix.show();
offset = (offset + 1) & 255;
delay(30);
}