Page 1 of 1

Neo pixel fade in/out?

Posted: Tue Sep 17, 2013 6:58 pm
by AlwaysHuman
Hey!

Does anyone know of a way to make neo pixel strips fade on and off? I'm trying to make something where when you tap a button, all the lights in the strip pop on, then fade off.

Thanks!

Re: Neo pixel fade in/out?

Posted: Tue Sep 17, 2013 7:21 pm
by EternalCore
Gimmy a few and I'll write you a quick example sketch. ;)

Re: Neo pixel fade in/out?

Posted: Tue Sep 17, 2013 7:46 pm
by EternalCore
Note: A more advanced example is 2 posts below this one. ;)

Here you go:

Code: Select all

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define PIXEL 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}


void loop() {
  int R = 0;
  int G = 0;
  int B = 0;
  //Fade in
  for(R && G && B; R<126 && G<126 && B<126; R++ && G++ && B++) {
    for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    delay(1);
  }
  //Fade Out
  for(R && G && B; R>-1 && G>-1 && B>-1; R-- && G-- && B--) {
    for(int j=0; j<strip.numPixels(); j++) {
      strip.setPixelColor(j, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    delay(1);
  }
}
-Enjoy.

Re: Neo pixel fade in/out?

Posted: Tue Sep 17, 2013 8:38 pm
by AlwaysHuman
Thank you so much!!!!! :D

Re: Neo pixel fade in/out?

Posted: Tue Sep 17, 2013 8:51 pm
by EternalCore
AlwaysHuman wrote:Thank you so much!!!!! :D
You're welcome. Here's a more advanced example that you can set the amount it updates by to speed it up:

Code: Select all

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define PIXEL 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}


void loop() {
  int R = 0;
  int G = 0;
  int B = 0;
  int finCount=5;
  int foutCount=5;
  int Rset = 125;
  int Gset = 125;
  int Bset = 125;
  int waitT = 5;
  //Fade in
  while(1){ //using an inf loop to be more custom.
  //Protect the strand from higher then 255 values
  if(R>255 || G>255 || B>255) { break; } //DO NOT DELETE OR ALTER THIS LINE.
    //break the inf loop if the color is higher then what its set at.
    if (R>Rset+1 && G>Gset+1 && B>Bset+1)  { 
      //ReSet the RGB to set values. 
      R=Rset;
      G=Gset;
      B=Bset;
      break; 
    } 
    //update the strip
    for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    //increase by the set amount
    R=R+finCount;
    G=G+finCount;
    B=B+finCount;
    delay(waitT);
  }
  //Fade Out
  while(1){ //using an inf loop to be more custom.
  //Protect the strand from higher then 255 values
  if(R>255 || G>255 || B>255) { break; } //DO NOT DELETE OR ALTER THIS LINE.
  //break the inf loop if the color is off
    if (R<0 && G<0 && B<0)  { 
      //ReSet the RGB to 0 values. 
      R=0;
      G=0;
      B=0;
      break; 
    } 
    //update the strip
    for(int j=0; j<strip.numPixels(); j++) {
      strip.setPixelColor(j, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    //Decrease by the set amount
    R=R-foutCount;
    G=G-foutCount;
    B=B-foutCount;
    delay(waitT);
  }
}
-Enjoy

Re: Neo pixel fade in/out?

Posted: Sat Dec 19, 2015 2:37 pm
by Gixxerfool
EternalCore wrote:
AlwaysHuman wrote:Thank you so much!!!!! :D
You're welcome. Here's a more advanced example that you can set the amount it updates by to speed it up:

Code: Select all

#include <Adafruit_NeoPixel.h>

#define PIN 6
#define PIXEL 60

Adafruit_NeoPixel strip = Adafruit_NeoPixel(PIXEL, PIN, NEO_GRB + NEO_KHZ800);

void setup() {
  strip.begin();
  strip.show(); // Initialize all pixels to 'off'
}


void loop() {
  int R = 0;
  int G = 0;
  int B = 0;
  int finCount=5;
  int foutCount=5;
  int Rset = 125;
  int Gset = 125;
  int Bset = 125;
  int waitT = 5;
  //Fade in
  while(1){ //using an inf loop to be more custom.
  //Protect the strand from higher then 255 values
  if(R>255 || G>255 || B>255) { break; } //DO NOT DELETE OR ALTER THIS LINE.
    //break the inf loop if the color is higher then what its set at.
    if (R>Rset+1 && G>Gset+1 && B>Bset+1)  { 
      //ReSet the RGB to set values. 
      R=Rset;
      G=Gset;
      B=Bset;
      break; 
    } 
    //update the strip
    for(int i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    //increase by the set amount
    R=R+finCount;
    G=G+finCount;
    B=B+finCount;
    delay(waitT);
  }
  //Fade Out
  while(1){ //using an inf loop to be more custom.
  //Protect the strand from higher then 255 values
  if(R>255 || G>255 || B>255) { break; } //DO NOT DELETE OR ALTER THIS LINE.
  //break the inf loop if the color is off
    if (R<0 && G<0 && B<0)  { 
      //ReSet the RGB to 0 values. 
      R=0;
      G=0;
      B=0;
      break; 
    } 
    //update the strip
    for(int j=0; j<strip.numPixels(); j++) {
      strip.setPixelColor(j, strip.Color(R, G, B));
      strip.show();
      delay(0);
    }
    //Decrease by the set amount
    R=R-foutCount;
    G=G-foutCount;
    B=B-foutCount;
    delay(waitT);
  }
}
-Enjoy
I realize this post is quite old, but I had a question on this sketch.

I am looking to have a neopixel jewel fade in once on reset. Can I copy the fade in from the first example, adjust the declarations and put it in my void setup?

Thanks in advance.

PS

I actually found your Cylon eye for the same project.