#include <Adafruit_NeoPixel.h>
#define PIN 2
#define NUMPIXELS 24
#define brightness 128 // jasność (0-255)
#define delay_time 50 // czas opóźnienia w ms
Adafruit_NeoPixel strip(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
// Definicja kolorów (RGB)
uint32_t colors[7];
uint32_t *template_colors = new uint32_t[NUMPIXELS];
void setup() {
strip.begin();
strip.show(); // inicjuj piksle
// ustawienia kolorów
colors[0] = strip.Color(brightness, 0, 0); // czerwony
colors[1] = strip.Color(0, brightness, 0); // zielony
colors[2] = strip.Color(0, 0, brightness); // niebieski
colors[3] = strip.Color(brightness, brightness, 0); // żółty
colors[4] = strip.Color(brightness, 0, brightness); // fioletowy
colors[5] = strip.Color(0, brightness, brightness); // cyjan
colors[6] = strip.Color(brightness, brightness, brightness); // biały
// inicjalizacja template
for (uint8_t i = 0; i < NUMPIXELS; i++) {
template_colors[i] = 0; // ustaw na czarno
}
// przypisanie kolorów do fragmentów
for (uint8_t i = 0; i < 3; i++) {
template_colors[i] = colors[0];
}
for (uint8_t i = 6; i < 9; i++) {
template_colors[i] = colors[1];
}
for (uint8_t i = 12; i < 15; i++) {
template_colors[i] = colors[2];
}
for (uint8_t i = 18; i < 21; i++) {
template_colors[i] = colors[3];
}
}
void loop() {
// przesuwanie w prawo
for (uint8_t shift = 0; shift < NUMPIXELS * 2; shift++) {
// przesuwanie tablicy w prawo
uint32_t last = template_colors[NUMPIXELS - 1];
for (uint8_t i = NUMPIXELS - 1; i > 0; i--) {
template_colors[i] = template_colors[i - 1];
}
template_colors[0] = last;
// wysyłanie do strip
for (uint8_t i = 0; i < NUMPIXELS; i++) {
strip.setPixelColor(i, template_colors[i]);
}
strip.show();
delay(delay_time);
}
// przesuwanie w lewo
for (uint8_t shift = 0; shift < NUMPIXELS * 2; shift++) {
// przesuwanie tablicy w lewo
uint32_t first = template_colors[0];
for (uint8_t i = 0; i < NUMPIXELS - 1; i++) {
template_colors[i] = template_colors[i + 1];
}
template_colors[NUMPIXELS - 1] = first;
// wysyłanie do strip
for (uint8_t i = 0; i < NUMPIXELS; i++) {
strip.setPixelColor(i, template_colors[i]);
}
strip.show();
delay(delay_time);
}
}