Neo pixel fade in/out?

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
AlwaysHuman
 
Posts: 13
Joined: Thu Mar 21, 2013 3:31 pm

Neo pixel fade in/out?

Post 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!

EternalCore
 
Posts: 239
Joined: Tue Jul 30, 2013 3:57 pm

Re: Neo pixel fade in/out?

Post by EternalCore »

Gimmy a few and I'll write you a quick example sketch. ;)

EternalCore
 
Posts: 239
Joined: Tue Jul 30, 2013 3:57 pm

Re: Neo pixel fade in/out?

Post 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.
Last edited by EternalCore on Tue Sep 17, 2013 11:10 pm, edited 1 time in total.

AlwaysHuman
 
Posts: 13
Joined: Thu Mar 21, 2013 3:31 pm

Re: Neo pixel fade in/out?

Post by AlwaysHuman »

Thank you so much!!!!! :D

EternalCore
 
Posts: 239
Joined: Tue Jul 30, 2013 3:57 pm

Re: Neo pixel fade in/out?

Post 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

User avatar
Gixxerfool
 
Posts: 46
Joined: Tue Dec 01, 2015 12:34 pm

Re: Neo pixel fade in/out?

Post 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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”