So my setup is i have strips that is separated into 4 pins and would like to modify this rainbow function from the neopixel so that it will work on 4 separate strip that are on 4 separate pins. I would like to look like strip number 2 is a continuation of strip number 1 and number 3 is to 2 and number 4 is to 3. A very cool feature about this function is the start and end is a continuation so this mean i basically have a ring setup.
void rainbow(int wait) {
// Hue of first pixel runs 5 complete loops through the color wheel.
// Color wheel has a range of 65536 but it's OK if we roll over, so
// just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
// means we'll make 5*65536/256 = 1280 passes through this outer loop:
for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
for(int i=0; i<strip.numPixels(); i++) { // For each pixel in strip...
// Offset pixel hue by an amount to make one full revolution of the
// color wheel (range of 65536) along the length of the strip
// (strip.numPixels() steps):
int pixelHue = firstPixelHue + (i * 65536L / strip.numPixels());
// strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
// optionally add saturation and value (brightness) (each 0 to 255).
// Here we're using just the single-argument hue variant. The result
// is passed through strip.gamma32() to provide 'truer' colors
// before assigning to each pixel:
strip.setPixelColor(i, strip.gamma32(strip.ColorHSV(pixelHue)));
}
strip.show(); // Update strip with new contents
delay(wait); // Pause for a moment
}
}
I do not understand how hue and gamma works so it a bit more tricky for me to modify this function.
Here is my attempt but my attempt is so crude and hoggs so much memory
void rainbow(int wait) {
unsigned int totalPixelCount = strip1.numPixels() + strip2.numPixels() + strip3.numPixels() + strip4.numPixels();
uint32_t pixelHueList [totalPixelCount];
for (long firstPixelHue = 0; firstPixelHue < 5 * 65536; firstPixelHue += 256) {
for (int i = 0; i < totalPixelCount; i++) {
int pixelHue = firstPixelHue + (i * 65536L / totalPixelCount);
pixelHueList[i] = strip1.gamma32(strip1.ColorHSV(pixelHue));
}
unsigned int j = 0;
for (j = j; j < strip1.numPixels(); j++)
strip1.setPixelColor(j,pixelHueList[j]);
for (j = j; j < strip1.numPixels() + strip2.numPixels(); j++)
strip2.setPixelColor(j,pixelHueList[j]);
for (j = j; j < strip1.numPixels() + strip2.numPixels() + strip3.numPixels(); j++)
strip3.setPixelColor(j,pixelHueList[j]);
for (j = j; j < strip1.numPixels() + strip2.numPixels() + strip3.numPixels() + strip3.numPixels(); j++)
strip3.setPixelColor(j,pixelHueList[j]);
strip1.show();
strip2.show();
strip3.show();
strip4.show();
delay(wait);
}
}
Is there a way to make it more efficient?
setPixelColor()
also need the index of the LED as parameter?pixelHueList[i] = (i, strip1.gamma32(
. I will look again at your question tomorrow. In my country its now time to go to bed :)