#include <Arduino.h>
#include "ws2812b.h"
// Platform constants
const uint16_t MAX_RESOLUTION = 120;
// Pixel formats — both exist, only GRB is used.
struct RGBPixelFormat {
uint8_t r, g, b;
};
struct GRBPixelFormat {
uint8_t g, r, b;
};
class Strip {
public:
static const uint8_t DATA_PIN = 2;
GRBPixelFormat pixels[MAX_RESOLUTION];
uint16_t length;
Strip(uint16_t length) {
this->length = length;
memset(pixels, 0, sizeof(pixels));
}
void update() {
ws2812b_write(DATA_PIN, (uint8_t*)pixels, length * sizeof(GRBPixelFormat));
}
};
Strip strip(20);
void setup() {
pinMode(Strip::DATA_PIN, OUTPUT);
for (uint16_t i = 0; i < strip.length; i++) {
uint8_t phase = i % 3;
if (phase == 0) {
strip.pixels[i].r = 200;
strip.pixels[i].g = 0;
strip.pixels[i].b = 0;
} else if (phase == 1) {
strip.pixels[i].r = 0;
strip.pixels[i].g = 155;
strip.pixels[i].b = 0;
} else {
strip.pixels[i].r = 0;
strip.pixels[i].g = 0;
strip.pixels[i].b = 255;
}
}
strip.update();
}
void loop() {
// static display
}