hi Mat13.. something wrong with your code here.. can you fix it?
thanks
Mat13:
I did that (but I didn't find it simplier :
... I had to pass sub strips instead of patterns to the functions.
I created a structure to store informations on the sub strips and its associated pattern.
This draft is compiling OK (but untested yet, my hardware is at home)

// StrandTest from AdaFruit implemented as a state machine
// pattern change by push button
// By Mike Cook Jan 2016
#define PINforControl 7 // pin connected to 1 single NeoPixels strip
#define NUMPIXELS1 20 // number of LEDs on strip
#include <Adafruit_NeoPixel.h>
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUMPIXELS1, PINforControl, NEO_GRB + NEO_KHZ800);
// Pattern types supported:
enum pattern_type { NONE, BLINK, RAINBOW, RAINBOW_CYCLE, THEATER_CHASE_RAINBOW, COLOR_WIPE, FADING };
struct subStrips {
uint16_t startIndex;
uint16_t nb_LED;
pattern_type activePattern;
unsigned long patternInterval;
unsigned long lastUpdate;
};
[b]// declare substrips
// the 20 LED are grouped by 7, 1, 1, 1, 1, 1, 7 (see image in the post)
subStrips stripRamp = {0, 7, THEATER_CHASE_RAINBOW, 20, 0 };
subStrips stripSingle1 = {7, 1, NONE, 20, 0 };
subStrips stripSingle2 = {8, 1, FADING, 20, 0 };
subStrips stripSingle3 = {9, 1, RAINBOW, 20, 0 };
subStrips stripSingle4 = {10, 1, BLINK, 20, 0 };
subStrips stripSingle5 = {11, 1, RAINBOW, 20, 0 };
subStrips stripAmbilight = {12, 7, RAINBOW_CYCLE, 20, 0 };[/b]
unsigned long patternInterval = 20 ; // time between steps in the pattern
unsigned long lastUpdate = 0 ; // for millis() when last update occoured
unsigned long intervals [] = { 20, 20, 50, 100 } ; // speed for each pattern
const byte button = 2; // pin to connect button switch to between pin and ground
void setup() {
strip.begin(); // This initializes the NeoPixel library.
wipe(); // wipes the LED buffers
pinMode(button, INPUT_PULLUP); // change pattern
}
void loop() {
// subStrip Ramp
if(millis() - stripRamp.lastUpdate > stripRamp.patternInterval) updateSubStripPattern(stripRamp);
// subStrip Single1
if(millis() - stripSingle1.lastUpdate > stripSingle1.patternInterval) updateSubStripPattern(stripSingle1);
//...
}
void updateSubStripPattern(subStrips &substripOut){ // out parameter
switch(substripOut.activePattern) {
case NONE :
wipeSubStrip(substripOut);
break;
case RAINBOW :
rainbow(substripOut);
break;
case RAINBOW_CYCLE:
rainbowCycle(substripOut);
break;
case THEATER_CHASE_RAINBOW:
theaterChaseRainbow(substripOut);
break;
case COLOR_WIPE:
colorWipe(substripOut, strip.Color(255, 0, 0)); // red
break;
case BLINK:
blinkEffect(substripOut, 111);
break;
}
}
void blinkEffect(subStrips &substrip, uint32_t color) {
for(int i=substrip.startIndex; i<(substrip.startIndex+substrip.nb_LED) ; i++) {
if (strip.getPixelColor(i) == 0) { strip.setPixelColor(i, color); }
else { strip.setPixelColor(i, 0); }
}
strip.show();
substrip.lastUpdate = millis(); // time for next change to the display
}
void rainbow(subStrips &substrip) { // modified from Adafruit example to make it a state machine
static uint16_t j=0;
for(int i=substrip.startIndex; i<(substrip.startIndex+substrip.nb_LED) ; i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
j++;
if(j >= 256) j=0;
substrip.lastUpdate = millis(); // time for next change to the display
}
void rainbowCycle(subStrips &substrip) { // modified from Adafruit example to make it a state machine
//
}
void theaterChaseRainbow(subStrips &substrip) { // modified from Adafruit example to make it a state machine
//
}
void colorWipe(subStrips &substrip, uint32_t c) { // modified from Adafruit example to make it a state machine
//
}
void wipeSubStrip(subStrips &substrip){ // clear all LEDs
for(int i=substrip.startIndex; i<(substrip.startIndex+substrip.nb_LED) ; i++) {
strip.setPixelColor(i, strip.Color(0,0,0));
}
strip.show();
// substrip.lastUpdate = millis(); // no need to refresh LED off
substrip.patternInterval = 10000000; // no need to refresh LED off
}
void wipe(){ // clear all LEDs
for(int i=0;i<strip.numPixels();i++){
strip.setPixelColor(i, strip.Color(0,0,0));
}
}
uint32_t Wheel(byte WheelPos) {
WheelPos = 255 - WheelPos;
if(WheelPos < 85) {
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
WheelPos -= 170;
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}