I've been trying to get colours fade into each other for a project I'm working on. I have achieved this with the rainbow effect that some from Adafruit's example code, however I want to be able to choose the colours (eg. dark blue into light blue).
I've got the colours changing and fading, however the fade turns off all the LEDs and starts to increase the brightness of the new colour. I need the colours to blend rather than fade out and increase in brightness.
Is anyone able to point me in the right direction?
#include "LPD8806.h"
#include "SPI.h"
#define stripSize 64
int nLEDs = 160;
int dataPin = 2;
int clockPin = 3;
// First parameter is the number of LEDs in the strand. The LED strips
// are 32 LEDs per meter but you can extend or cut the strip. Next two
// parameters are SPI data and clock pins:
LPD8806 strip = LPD8806(64, dataPin, clockPin);
// You can optionally use hardware SPI for faster writes, just leave out
// the data and clock pin parameters. But this does limit use to very
// specific pins on the Arduino. For "classic" Arduinos (Uno, Duemilanove,
// etc.), data = pin 11, clock = pin 13. For Arduino Mega, data = pin 51,
// clock = pin 52. For 32u4 Breakout Board+ and Teensy, data = pin B2,
// clock = pin B1. For Leonardo, this can ONLY be done on the ICSP pins.
//LPD8806 strip = LPD8806(nLEDs);
void setup() {
// Start up the LED strip
strip.begin();
// Update the strip, to start they are all 'off'
strip.show();
}
void loop() {
//turnAllOn(strip.Color(30,30,30),4000);
fade(0, 127, 0, 100); //red, green, blue, delay - fade up all pixels one color
//turnAllOn(strip.Color(30,100,30),4000);
fade(50, 127, 02,100); //red, green, blue, delay - fade up all pixels one color
//turnAllOn(strip.Color(100,30,100),4000);
fade(50, 127, 50, 100); //red, green, blue, delay - fade up all pixels one color
}
void fade(uint32_t r, uint32_t g, uint32_t b, uint32_t wait) {
int i, j;
for (j=0; j < 384; j++) {
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, strip.Color((r*j)/1000,(g*j)/1000,(b*j)/1000));
}
strip.show();
}
delay(wait);
}
void turnAllOn(uint32_t c, uint32_t wait) {
int i;
for (i=0; i < strip.numPixels(); i++) {
strip.setPixelColor(i, c); // turn all pixels on
}
strip.show(); // write all the pixels out
delay(wait);
}
uint32_t Wheel(uint16_t WheelPos)
{
byte r, g, b;
switch(WheelPos / 128)
{
case 0:
r = 127 - WheelPos % 128; //Red down
g = WheelPos % 128; // Green up
b = 0; //blue off
break;
case 1:
g = 127 - WheelPos % 128; //green down
b = WheelPos % 128; //blue up
r = 0; //red off
break;
case 2:
b = 127 - WheelPos % 128; //blue down
r = WheelPos % 128; //red up
g = 0; //green off
break;
}
return(strip.Color(r,g,b));
}