I have a Doctor Who messenger box gizmo that I have always liked. What it does is simply fade between all the colors (RGB and everything in between). I want to do that with a strand of WS2801 Lights hooked up to my Uno. I want the lights to fade between RGB (and everything in between that the lights are capable of) over a period of perhaps 6 minutes (equal time for each color if possible). Also, I want every light on the strand to be in sync. If the first bulb is green then the last is green, etc...
Now, I got the lights to do what I want, for the most part, by hobbling this code together from the sample code (like a monkey wacking a wrench against a pipe till it stops leaking):
Code: Select all
#include "SPI.h"
#include "Adafruit_WS2801.h"
int dataPin = 2; // Yellow wire on Adafruit Pixels
int clockPin = 3; // Green wire on Adafruit Pixels
Adafruit_WS2801 strip = Adafruit_WS2801((uint16_t)7, (uint16_t)7, dataPin, clockPin);
void setup() {
strip.begin();
// Update LED contents, to start they are all 'off'
strip.show();
}
void loop() {
rainbow(20);
}
void rainbow(uint8_t wait) {
int i, j;
for (j=0; j < 256; j++) { // 3 cycles of all 256 colors in the wheel
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel( (i + j) % 255));
}
strip.show(); // write all the pixels out
delay(2400);
}
}
/* Helper functions */
uint32_t Color(byte r, byte g, byte b)
{
uint32_t c;
c = r;
c <<= 8;
c |= g;
c <<= 8;
c |= b;
return c;
}
uint32_t Wheel(byte WheelPos)
{
if (WheelPos < 85) {
return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if (WheelPos < 170) {
WheelPos -= 85;
return Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
- Why does the time between each color transition change when I change the number next to the rainbow variable (20 in this case)?
Am I right in assuming that the delay (2400 in this case) it the main factor in the color fade time?
Am I properly using all the colors these lights are capable of?
Dan