Fade between color1 and color2

Hi. This is my first program project and I fear I have bitten off more than I can chew. I am attempting to make a skirt that changes colors using Neopixel strips. I have 12 strips, wired into 6 pins. Each pin has 54 LEDs. I am using a Feather m0 Proto board. I hope to eventually add a bodice, so we are talking over 900 pixels when all is said and done. Should I just buy a Mega or will the Feather be able to handle those numbers?

But more importantly, I would like to get this skirt code to work first. I would like to start in blue, delay for 10 seconds, then fade all LEDs at once to pink, then delay for 10 seconds, fade back to blue and have this on a loop. I bought the Neopixel strips with the intention of doing some fun programming, like doing a color change sweep from pin 1 over to pin 6 and a star burst from the middle of pin 3. And to have those programs be switch activated. If I can figure out this basic color fade problem, if anyone can give me some advice on where to start with these ideas, that would be amazing. Could I get a circular dial to go from blue to pink as I turn it? That would be much easier than coding I think, even if it would be a temporary fix.

I know Adafruit has their Fade in their library, but I cannot for the life of me get it to work, especially as it looks like Fade is actually Dim. I used their Fade code from their Multitasking the Arudino, but it's just part of what I need and I can't fill in the blanks to make it a full working code.

#define DATA_PIN    1
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS    54        // Change this to reflect the number of LEDs you have
#define BRIGHTNESS  150       // Set Brightness here
Adafruit_NeoPixel strip = Adafruit_NeoPixel(54, 1, NEO_GRB + NEO_KHZ800);

#define DATA_PIN    2
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS    54        // Change this to reflect the number of LEDs you have
#define BRIGHTNESS  150       // Set Brightness here
Adafruit_NeoPixel strip = Adafruit_NeoPixel(54, 2, NEO_GRB + NEO_KHZ800);

#define DATA_PIN    3
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS    54        // Change this to reflect the number of LEDs you have
#define BRIGHTNESS  150       // Set Brightness here
Adafruit_NeoPixel strip = Adafruit_NeoPixel(54, 3, NEO_GRB + NEO_KHZ800);

#define DATA_PIN    4
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS    54        // Change this to reflect the number of LEDs you have
#define BRIGHTNESS  150       // Set Brightness here
Adafruit_NeoPixel strip = Adafruit_NeoPixel(54, 4, NEO_GRB + NEO_KHZ800);

#define DATA_PIN    5
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS    54        // Change this to reflect the number of LEDs you have
#define BRIGHTNESS  150       // Set Brightness here
Adafruit_NeoPixel strip = Adafruit_NeoPixel(54, 5, NEO_GRB + NEO_KHZ800);

#define DATA_PIN    6
#define LED_TYPE    WS2812
#define COLOR_ORDER GRB
#define NUM_LEDS    54        // Change this to reflect the number of LEDs you have
#define BRIGHTNESS  150       // Set Brightness here
Adafruit_NeoPixel strip = Adafruit_NeoPixel(54, 6, NEO_GRB + NEO_KHZ800);

    void loop() 
    // Initialize for a Fade
    void Fade(uint32_t color1, uint32_t color2, uint16_t steps, uint8_t interval, direction dir = FORWARD)
    {
        ActivePattern = FADE;
        Interval = 100;
        TotalSteps = 5;
        Color1 = {255,00,100};
        Color2 = {10,10,255};
        Index = 0;
        Direction = dir;
    }

My first problem is the error comes up "exit status 1 'Adafruit_NeoPixel' does not name a type'" I have no idea what that means. And I can't get past that to see if this code will work. Although I highly doubt this is the only problem with my code. Any assistance would be much appreciated.

Your first problem is caused because you need to include Adafruit_NeoPixel.h which will hold the definition for the type, not just take part of the library and copy it. The Fade function looks like an initialisation function/method that has been taken from a library, not an actual function that does something.

Also, right from the start, you have no setup function and your loop needs curly braces and needs to contain code that actually does something.

Ok, like I said this is my first time trying code. I clearly don’t have all the pieces together. So how does this look if I wanted to just work one pin (although showing me how to code multiple pins would save me a step)?

#include <Adafruit_NeoPixel.h>

int PIN = 3;
int totalLEDs = 54;
int ledFadeTime = 5;

Adafruit_NeoPixel strip = Adafruit_NeoPixel(54, 3, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show();


    startColor = strip(10, 10, 255);
    endColor = strip(255, 0, 100);

}// put your setup code here, to run once:

}

void loop() {

  for (int i = 255; i > 0; i--)
  {
    startColor = strip(10, 10, 255);
    endColor = strip(255, 0, 100);
      strip.show();
      delay(10);
  }
}

I don’t think that is even close to what you want. You have and extra ‘}’ after setup(). You are calling the ‘strip’ object as if it were a function. You should be calling a “method” (member function) of the object like:

strip.setColor(10, 10, 255);

Almost every library comes with at least one example sketch. Study the example sketches. Start with the one that most closely matches your desired behavior. Borrow pieces from other examples as necessary.

Adafruit typically has full-blown tutorials for their devices. Check the page for the NeoPixel strips.

If the strip library doesn’t include a ‘cross fade’ method you will have to fade in steps by setting the initial color and then step through intermediate colors until you get to the destination color. You can use simple math or the map() function:

void loop() {
  for (int i=0; i<256; i++) {
    int red = map(i, 0, 255, 10, 255);
    int green = map(i, 0, 255, 10, 0);
    int blue = map(i, 0, 255, 255, 100);
    strip.setColor(red, green, blue);
    strip.show();
    delay(10);
  }
}

Hi, Another detail that hasn't been mentioned is that I think you need to give your several strips seperate names, eg:

Adafruit_NeoPixel strip = Adafruit_NeoPixel(54, 3, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(54, 2, NEO_GRB + NEO_KHZ800);

At least "strip_3" and "strip_2" if you can't think of more descriptive names.

best, Michael

The preprocessor directive #define is not a comment. Your code shows many #define for the same names. But then you never use those names because you just wrote the values into the following line.

Those lines redefine the same variable strip over and over. All the earlier ones are forgotten.

Like John said, fading between colours requires individually fading red, green and blue.

With that many strips and numbered variables, look into arrays. That will make the code easier to write for as many strips as you need.

This is the kind of programming you will need to cross-fade six strips of 60 pixels:

#include <Adafruit_NeoPixel.h>

const int NUM_PIXELS = 60;
const int NUM_STRIPS = 6;

// An array of the pin numbers for the strips
const int Pins[NUM_STRIPS] = {2, 3, 4, 5, 6, 7};


// Parameter 1 = number of pixels in strip
// Parameter 2 = Arduino pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
//   NEO_RGBW    Pixels are wired for RGBW bitstream (NeoPixel RGBW products)
Adafruit_NeoPixel Strips[NUM_STRIPS] = {
  Adafruit_NeoPixel(NUM_PIXELS, Pins[0], NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_PIXELS, Pins[1], NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_PIXELS, Pins[2], NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_PIXELS, Pins[3], NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_PIXELS, Pins[4], NEO_GRB + NEO_KHZ800),
  Adafruit_NeoPixel(NUM_PIXELS, Pins[5], NEO_GRB + NEO_KHZ800)
};

const uint32_t Blue = Adafruit_NeoPixel::Color(10, 10, 255);
const uint32_t Pink = Adafruit_NeoPixel::Color(255, 0, 100);


// IMPORTANT: To reduce NeoPixel burnout risk, add 1000 uF capacitor across
// pixel power leads, add 300 - 500 Ohm resistor on first pixel's data input
// and minimize distance between Arduino and first pixel.  Avoid connecting
// on a live circuit...if you must, connect GND first.

void setup() {
  for (int strip = 0; strip < NUM_STRIPS; strip++) {
    Strips[strip].begin();
  }
  setAllStrips(Blue);
}

void loop() {
  delay(30000UL);
  crossFade(Blue, Pink, 10UL);
  delay(30000UL);
  crossFade(Pink, Blue, 10UL);
}

void setAllStrips(const uint32_t color) {
  byte red = (color >> 16) & 0xff;
  byte green = (color >> 8) & 0xff;
  byte blue = color & 0xff;
  setAllStrips(red, green, blue);
}

void setAllStrips(byte red, byte green, byte blue) {
  // for each strip
  for (int strip = 0; strip < NUM_STRIPS; strip++) {
    // for each pixel
    for (int pixel = 0; pixel < NUM_PIXELS; pixel++) {
      Strips[strip].setPixelColor(pixel, red, green, blue);
    }
    Strips[strip].show(); // Output to strip
  }
}

void crossFade(const uint32_t startColor, const uint32_t endColor, unsigned long speed) {
  byte startRed = (startColor >> 16) & 0xff;
  byte startGreen = (startColor >> 8) & 0xff;
  byte startBlue = startColor & 0xff;

  byte endRed = (endColor >> 16) & 0xff;
  byte endGreen = (endColor >> 8) & 0xff;
  byte endBlue = endColor & 0xff;

  // for each step in the cross-fade
  for (int step = 0; step < 256; step++) {
    byte red = map(step, 0, 255, startRed, endRed);
    byte green = map(step, 0, 255, startGreen, endGreen);
    byte blue = map(step, 0, 255, startBlue, endBlue);
    setAllStrips(red, green, blue);
    delay(speed);
  }
}