hello there
i am at my whits end trying to figure out how to get a led to fade in and stay at full brightness until the next trigger is activated. iv tried many different ways of achieving this with no joy.
here's the code, what i am trying to achieve is when digitalValue goes high the specified led turns on with a gradual fade in then stay on as long as the input stays high, then fade out when the next trigger is activated.
#include <FastLED.h>
#define NUM_LEDS 5
#define DATA_PIN 12
#define CLOCK_PIN 13
#define COLOR_ORDER GRB
CRGB leds[NUM_LEDS];
#define BRIGHTNESS 100
const int input1 = 3;
const int input2 = 4;
const int input3 = 5;
const int input4 = 6;
uint8_t hue = 160;
uint8_t sat = 255;
uint8_t val = 0;
void setup() {
Serial.begin(115200);
delay( 2000 );
FastLED.addLeds<P9813, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS); // BGR ordering is typical
FastLED.setBrightness(BRIGHTNESS);
pinMode(input1, INPUT);
pinMode(input2, INPUT);
pinMode(input3, INPUT);
pinMode(input4, INPUT);
}
void loop() {
int digitalValue1 = digitalRead(input1);
int digitalValue2 = digitalRead(input2);
int digitalValue3 = digitalRead(input3);
int digitalValue4 = digitalRead(input4);
for(int i = 0; i < NUM_LEDS; i++ )
if (digitalValue1 == HIGH){
leds[0].setRGB (0, 0, 255);
leds[1].setRGB (0, 0, 0);
leds[2].setRGB (0, 0, 0);
leds[3].setRGB (0, 0, 0);
leds[4].setRGB (0, 0, 0);
FastLED.show();
}
else if (digitalValue2 == HIGH){
leds[0].setRGB (0, 0, 0);
leds[1].setRGB (0, 0, 255);
leds[2].setRGB (0, 0, 0);
leds[3].setRGB (0, 0, 0);
leds[4].setRGB (0, 0, 0);
FastLED.show();
}
else if (digitalValue3 == HIGH){
leds[0].setRGB (0, 0, 0);
leds[1].setRGB (0, 0, 0);
leds[2].setRGB (0, 0, 255);
leds[3].setRGB (0, 0, 0);
leds[4].setRGB (0, 0, 0);
FastLED.show();
}
else if (digitalValue4 == HIGH){
leds[0].setRGB (0, 0, 0);
leds[1].setRGB (0, 0, 0);
leds[2].setRGB (0, 0, 0);
leds[3].setRGB (0, 0, 255);
leds[4].setRGB (0, 0, 0);
FastLED.show();
}
else{ leds[i].setRGB (255, 255, 255);
FastLED.show();
}
}
i am a extreme novice at coding so iv probably made this look way more complicated than it needs to be. also its my first time posting anything to this site so if iv posted this in the wrong place or done anything wrong i can only apologise.
any help will be much appreciated. ![]()
P9813_led_driver_basic.ino (1.79 KB)