Hi all, this is my first post here! I'm newbie of arduino and sorry for my noobism.
I've this setup:
This project is for my car headlights. A dynamic turn signal and DRL.
the turn signal work great, but the fade and stay function for DRL is very difficult for me.
This is my code
void RGBLoop(){
for(int j = 0; j < 3; j++ ) {
// Fade IN
for(int k = 0; k < 256; k++) {
switch(j) {
case 0: setAll(k,0,0); break;
case 1: setAll(0,k,0); break;
case 2: setAll(0,0,k); break;
}
showStrip();
delay(3);
}
I try to turn on led strips in white color and fade from 0 to 255 and stay on but when fading to max brightness it's start to cycle again and again. How i can stop it to the max?
After this i try simply to turn on directly without fading (just to try) but when led goes on, the light flickering.
This is code
#include "FastLED.h"
#define NUM_LEDS 72
CRGB leds[NUM_LEDS];
#define PIN 6
const int buttonPin2 = 2;
const int buttonPin3 = 3;
int buttonState2 = 0;
int buttonState3 = 0;
int fadeAmount = 5; // Set the amount to fade I usually do 5, 10, 15, 20, 25 etc even up to 255.
void setup()
{
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(buttonPin3, INPUT_PULLUP);
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
//FastLED.addLeds<NEOPIXEL, 8>(leds[0], NUM_LEDS); //led strip for front left
//FastLED.addLeds<NEOPIXEL, 9>(leds[1], NUM_LEDS); //led strip for front right
}
// *** REPLACE FROM HERE ***
void TurnSignal() {
meteorRain(0xff,0x66,0x00,10, 40, true, 3);
}
void meteorRain(byte red, byte green, byte blue, byte meteorSize, byte meteorTrailDecay, boolean meteorRandomDecay, int SpeedDelay) {
//setAll(0,0,0);
for(int i = 0; i < NUM_LEDS+NUM_LEDS; i++) {
// fade brightness all LEDs one step
for(int j=0; j<NUM_LEDS; j++) {
if( (!meteorRandomDecay) || (random(10)>5) ) {
fadeToBlack(j, meteorTrailDecay );
}
}
// draw meteor
for(int j = 0; j < meteorSize; j++) {
if( ( i-j <NUM_LEDS) && (i-j>=0) ) {
setPixel(i-j, red, green, blue);
}
}
showStrip();
delay(SpeedDelay);
}
}
void fadeToBlack(int ledNo, byte fadeValue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
uint32_t oldColor;
uint8_t r, g, b;
int value;
oldColor = strip.getPixelColor(ledNo);
r = (oldColor & 0x00ff0000UL) >> 16;
g = (oldColor & 0x0000ff00UL) >> 8;
b = (oldColor & 0x000000ffUL);
r=(r<=10)? 0 : (int) r-(r*fadeValue/256);
g=(g<=10)? 0 : (int) g-(g*fadeValue/256);
b=(b<=10)? 0 : (int) b-(b*fadeValue/256);
strip.setPixelColor(ledNo, r,g,b);
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
leds[ledNo].fadeToBlackBy( fadeValue );
#endif
}
void DRL() {
fill_solid(leds, NUM_LEDS, CRGB::Blue); //set entire LED strip to Blue
}
void loop() {
buttonState2 = digitalRead(buttonPin2);
if (buttonState2 == LOW) {
TurnSignal();
} else {
FastLED.clear();
FastLED.show();
}
buttonState3 = digitalRead(buttonPin3);
if (buttonState3 == LOW) {
DRL();
} else {
FastLED.clear();
FastLED.show();
}
}
// *** REPLACE TO HERE ***
void showStrip() {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.show();
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
FastLED.show();
#endif
}
void setPixel(int Pixel, byte red, byte green, byte blue) {
#ifdef ADAFRUIT_NEOPIXEL_H
// NeoPixel
strip.setPixelColor(Pixel, strip.Color(red, green, blue));
#endif
#ifndef ADAFRUIT_NEOPIXEL_H
// FastLED
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();
}
But if i try to use the function in a new sketch, the led goes on correctly
#include "FastLED.h"
#define NUM_LEDS 72
CRGB leds[NUM_LEDS];
#define PIN 6
void setup() {
// put your setup code here, to run once:
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
}
void loop() {
// put your main code here, to run repeatedly:
fill_solid(leds, NUM_LEDS, CRGB::Blue); //set entire LED strip to Blue
//showStrip();
}
Someone can help me? Thank you