-------------------------------------------------
//dress_shirt_v5_slow_color
//dress shirt slow color change, Paul Mirel 20131214
//Open Source. You may use or modify this code any way you wish.
//this code sets two pixels to two different, slowly changing colors. Both start green, and then drift away from each other.
//I based it on the Adafruit NeoPixel sample code.
//The recursive delay I added to rainbow() is a brute force way to get longer delays than the 8 bit integer allows.
#include <Adafruit_NeoPixel.h>
#define PIN 6
// Parameter 1 = number of pixels in strip
// Parameter 2 = 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_GRB Pixels are wired for GRB bitstream (most NeoPixel products)
Adafruit_NeoPixel strip = Adafruit_NeoPixel(2, PIN, NEO_GRB + NEO_KHZ800);
void setup() {
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
rainbow(32); //slow color change for cocktail parties
//rainbow(4); //faster color change for debugging
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
strip.setPixelColor(0, Wheel(j & 255));
strip.setPixelColor(1, Wheel((255-j) & 255));
//strip.setPixelColor(1, Wheel((j+16) & 255));
strip.show();
for (i=0; i< wait; ++i) {
delay (wait);
}
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
No comments:
Post a Comment