Hardware components | ||||||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
![]() |
| × | 1 | |||
| × | 1 | ||||
Software apps and online services | ||||||
![]() |
|
Chaotic colourful Wave Animation for 8x8 ws2812b matrix.
Code is in void and void is called in loop.
Connection Resistor to Matrix on PIN 5.
#include "Adafruit_NeoPixel.h"
#define WS2812b_PIN 5
#define WS2812b_PIXELS 64
#define WS2812b_WIDTH 8
#define WS2812b_HEIGHT 8
Adafruit_NeoPixel WS2812b = Adafruit_NeoPixel(WS2812b_PIXELS, WS2812b_PIN, NEO_GRB + NEO_KHZ800);
void setup() {
Serial.begin(9600);
WS2812b.begin();
WS2812b.clear();
WS2812b.show();
}
void chaoticWaveAnimation() {
delay(30);
WS2812b.setBrightness(100);
static uint8_t hueOffset = 0;
static uint8_t wavePos[WS2812b_WIDTH];
for (int i = 0; i < WS2812b_WIDTH; i++) {
wavePos[i] += random(1, 4);
if (wavePos[i] >= WS2812b_HEIGHT * 2) {
wavePos[i] = 0;
}}
WS2812b.clear();
for (int x = 0; x < WS2812b_WIDTH; x++) {
for (int y = 0; y < WS2812b_HEIGHT; y++) {
int distance = abs(y - (wavePos[x] % WS2812b_HEIGHT));
if (distance < 3) {
float wave = sin((hueOffset + x + y) * 0.1);
uint8_t brightness = 128 + (127 * wave);
uint8_t hue = hueOffset + (x * 10) + (y * 5);
uint32_t color = WS2812b.ColorHSV(hue * 256, 255, brightness);
int pixelIndex = y * WS2812b_WIDTH + x;
WS2812b.setPixelColor(pixelIndex, color);
}}}
WS2812b.show();
hueOffset += 2;
}
void loop() {
chaoticWaveAnimation();
}
Comments
Please log in or sign up to comment.