//sketch fills a led stick with pattern defined in array pattern and move it left to right
#include <Adafruit_NeoPixel.h>
#define ledPin A0
#define ledCount 8
Adafruit_NeoPixel strip(ledCount, ledPin, NEO_GRB + NEO_KHZ800);
//declararion of pattern colors
uint32_t red = strip.Color(255, 0, 0);
uint32_t green = strip.Color(0, 255, 0);
uint32_t blue = strip.Color(0, 0, 255);
uint32_t magenta = strip.Color(255, 0, 255);
uint32_t black = strip.Color(0, 0, 0);
uint32_t white = strip.Color(255, 255, 255);
uint32_t pattern[] = {red, red, blue, blue};
int patCnt = 4; //length of pattern array
void setup() {
//activating led stick
strip.begin();
strip.show();
strip.setBrightness(100); //setup a brightness
}
void loop() {
//clearing strick and call pattern moove function
//
strip.clear();
patternMoove(pattern, 150);
}
//the function fills stick with the pattern pat[]
//the parameter wait describes a delay between changes of frames
void patternMoove(uint32_t pat[], int wait) {
//declaration and creation of working pattern array
uint32_t patternCopy[patCnt];
for (int patId=0; patId<patCnt; patId++) {
patternCopy[patId] = pattern[patId];
}
for (int i = 0; i < patCnt; i++) {
//filling stick with pattern
int m = 0;
for (int n = 0; n < ledCount; n++) {
strip.setPixelColor(n, patternCopy[m]);
m++;
if (m==patCnt) {
m=0;
}
}
//showing current stick pattern
strip.show();
delay(wait);
//change the pattern, first becomes second, second third and last color becomes first
uint32_t tempCol = patternCopy[patCnt-1];
for (int cnt=patCnt-1; cnt>0; cnt--) {
patternCopy[cnt]=patternCopy[cnt-1];
}
patternCopy[0]=tempCol;
}
}