Hi everyone,
I am currently trying to fade between custom colours using led pixels, driver ws2182. I have successfully managed to fade between straight RGB values with no problem as you can see in the code below. In fact the result is very effective. However as soon as I try and enter a custom RGB value, for example 255,50,0 I start getting strange results. The led begins cycling through the individual colours one at a time rather than fading.
Can anyone offer any advice as to why this is happening?
I am new to Arduino so I appreciate your patience!
Thanks in advance
#include <Adafruit_NeoPixel.h>
#define PIN 5
#define NUM_LEDS 4
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
int time = 5;
void setup() {
Serial.begin(9600);
strip.begin();
strip.show(); // Initialize all pixels to 'off'
}
void loop() {
FadeInLED0(255, 0, 0, 255, 0, 0); //1 sunrise 6am in
FadeInLED0(0,255,0, 255, 0, 0); // 7am
FadeInLED0(0,0,255, 0, 255, 0); // 7am
FadeInLED0(255,0,0, 0, 0, 255); // 7am
}
void FadeInLED0(byte red, byte green, byte blue, byte Rold, byte Gold, byte Bold)
{
float r, g, b;
int m=1;
int Rdiff=(Rold-red);
int Gdiff=(Gold-green);
int Bdiff=(Bold-blue);
int RStep = Rdiff/256;
int GStep = Gdiff/256;
int BStep = Bdiff/256;
for(int k = 0; k < 256; k=k+1)
{
r=Rold+Rdiff*(k);
g=Gold+Gdiff*(k);
b=Bold+Bdiff*(k);
strip.show();
strip.setPixelColor(0,r,g,b);
delay (time);
Serial.println (g);
}}