@OP: hi, Here's 2 fade in/out examples I made, for the NeoPixels but they can easily be adapted for the WWS2801 strips, that you may use:
This is a simple example:
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);
}
}
And here's a more complex example:
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