This is the whole sketch
#include <Adafruit_NeoPixel.h>
#define PIN 11
Adafruit_NeoPixel strip = Adafruit_NeoPixel(100, PIN, NEO_GRB + NEO_KHZ800);
#define COLOR(r,g,b) ( (uint32_t)r << 16) | ((uint32_t)g << 8) | b
uint32_t BLACK = COLOR(0,0,0);
uint32_t WHITE = COLOR(255,255,255);
uint32_t RED = COLOR(255,0,0);
uint32_t GREEN = COLOR(0,255,0);
uint32_t BLUE = COLOR(0,0,255);
uint32_t PURPLE = COLOR(51,0,102);
uint32_t PINK = COLOR(204,0,204);
uint32_t YELLOW = COLOR(255,198,7);
uint32_t Wheel(byte WheelPos)
{
if(WheelPos < 85)
{
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if(WheelPos < 170)
{
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
else
{
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
class Pattern
{
public:
virtual void Init(void)
{}
virtual void Run(long time)
{}
static void SetAll (uint32_t color)
{
for (uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, color);
}
strip.show();
}
static void SetSomeLeds (uint32_t color, int numberLeds)
{
for (uint16_t i=0; i<numberLeds; i++) {
strip.setPixelColor(i, color);
}
strip.show();
}
};
class Color : public Pattern
{
public:
uint32_t m_color;
Color (uint32_t color)
{
m_color = color;
}
void Init (void)
{
Pattern::SetAll(m_color);
}
};
class RGB : public Color
{
public:
RGB (byte red, byte green, byte blue) :
Color (COLOR (red, green, blue))
{}
};
class FlashyRainbow : public Pattern
{
byte base;
void Run (long elapsed)
{
uint16_t j;
elapsed = elapsed % 400;
if (elapsed < 200)
{
for(j=0; j<strip.numPixels(); j++)
{
int val = elapsed + j * 256 / strip.numPixels();
strip.setPixelColor(j, Wheel(val % 256 ));
}
strip.show();
}
else
{
Pattern::SetAll(BLACK);
}
}
};
class FlashyYellow: public Pattern
{
void Init (void)
{
Pattern::SetAll(YELLOW);
}
void Run (long elapsed)
{
elapsed = elapsed % 400;
if (elapsed < 200)
{
Pattern::SetAll(YELLOW);
} else {
Pattern::SetAll(BLACK);
}
}
};
typedef struct {
int time;
Pattern *pattern;
} Effect;
Effect effects[] = {
{6250, new FlashyRainbow()}, // 10 seconds of flashy rainbow
{500, new Color(RED)}, // 1 seconds red
{500, new Color(GREEN)}, // 1 seconds green
{1500, new Color(PURPLE)}, // 1 seconds purple
{500, new Color(PINK)}, // 1 seconds pink
{500, new Color(BLUE)}, // 1 seconds blue
{4000, new Color(YELLOW)}, // 3 seconds yellow
{4500, new FlashyRainbow()}, // 6 seconds of flashy rainbow
{250, new Color(BLACK)}, // 1 seconds red
{4000, new FlashyRainbow()}, // 6 seconds of flashy rainbow
{250, new Color(RED)},// 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{250, new Color(RED)}, // 1 seconds red
{250, new Color(BLACK)}, // 1 seconds red
{1675, new Color(RED)}, // 2 seconds red
{2750, new Color(GREEN)}, // 2 seconds green
{950, new Color(RED)}, // 1 seconds red
{2900, new Color(GREEN)}, // 3 seconds green
{3000, new FlashyRainbow()}, // 10 seconds of flashy rainbow
{0, NULL}
};
class EffectController
{
Effect *m_effects;
int m_index = 0;
long m_start;
public:
EffectController (Effect effects [])
{
m_effects = effects;
}
void Start (void)
{
Serial.print ("start ");
Serial.println();
strip.begin();
strip.show(); // Initialize all pixels to 'off'
m_index = 0;
}
void ShowStatus (void)
{
Serial.print ("time ");
Serial.print ((long)(millis()-m_start));
Serial.print (" track ");
Serial.print (m_index);
Serial.println();
}
void Run (void)
{
long elapsed;
//long this_time = m_effects[m_index].time * 1000;
long this_time = m_effects[m_index].time;
if (m_index == 0)
m_start = millis();
if (this_time > 0)
{
ShowStatus();
long track_start = millis();
m_effects[m_index].pattern->Init();
do
{
elapsed = millis() - track_start;
m_effects[m_index].pattern->Run(elapsed);
} while (elapsed < this_time);
m_index++;
if (m_effects[m_index].time == 0)
{
// finished
Serial.print ("time ");
Serial.print ((long)(millis()-m_start));
Serial.print (" finished");
Serial.println();
Pattern::SetAll(COLOR(0,0,0));
}
}
}
};
EffectController controller (effects);
void setup() {
int j;
Serial.begin(115200);
Pattern::SetSomeLeds (RED, 1);
for (j=5; j>0; j--)
{
Pattern::SetSomeLeds (GREEN, j);
delay (1000);
}
controller.Start();
}
void loop() {
controller.Run();
}