Hello,
I'm a beginner at coding for the Arduino and I would like some help with my current project. I'm trying to make my LED strip fade in and out like its breathing. Through my research, I have found some code that works for me, but I'm trying to make the fade in and out times longer. I've successfully been able to delay the time in between the fade in and fade out. Also, I have been able to make the fade-out time longer. However, the fade-in time is still too short for my liking and that's where I need some help. I'm trying to make the fade-in time longer and not as abrupt. I'm using an Arduino Mini Pro with a WS2812B LED strip. Here is the code that I have been working with.
#include <FastLED.h>
#define NUM_LEDS 100
CRGB leds[NUM_LEDS];
#define PIN 3
void setup()
{
FastLED.addLeds<WS2812B, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop() {
FadeInOut(0xff, 0x00, 0x00);
}
void FadeInOut(byte red, byte green, byte blue){
float r, g, b;
for(int k = 0; k < 100; k=k+1) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
showStrip();
}
for(int k = 100; k >= 0; k=k-2) {
r = (k/256.0)*red;
g = (k/256.0)*green;
b = (k/256.0)*blue;
setAll(r,g,b);
delay(100); /* effects the fade out time */
showStrip();
}
delay(1000); /* effects the time inbetween fades */
}
void showStrip() {
FastLED.show();
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifndef ADAFRUIT_NEOPIXEL_H
leds[Pixel].r = red;
leds[Pixel].g = green;
leds[Pixel].b = blue;
#endif
}
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
setPixel(i, red, green, blue);
}
showStrip();
}
Please let me know if there is a better way or different functions that allow for the fade in and out. Thank you