Hi All,
I hope you'll tolerate a question from someone who is new to Arduino programming.
The application will be instrument cluster lights in my old Fiat restoration project.
The LEDs are WS2811 controlled and the board is a Leonardo. I've confirmed that they are individually addressable and not the chips that control 3 LEDs with one chip.
In the final application, a 12V signal from the car will go through an optocoupler 12V-->5V, but right now on the bench I'm just using 5V as a trigger.
Instead of powering an old 12V incandescent light, the 12V signal from the car will go through the optocoupler to the Arduino and then power one the specific addressable LEDs.
My code is below. After an initial start-up routine that cycles all of the lights on and off (and works fine), I'd like it to turn on individual lights when a 5V signal goes to one of the analog pins and turn it off when the power is disconnected. The problem I am having is that once I put 5V to any of the four assigned pins, all 4 lights power on. When I disconnect the 5V, all 4 lights turn off. I can't figure out how to get just one light to turn on by providing signal to one of the analog pins.
Can some kind soul take a look at my code and guide? Thank you!!
#include <FastLED.h>
#define NUM_LEDS 16
#define LED_PIN 2
CRGB leds[NUM_LEDS];
void setup() {
delay(2000);
FastLED.addLeds<WS2811, LED_PIN, RGB>(leds, NUM_LEDS);
FastLED.setBrightness(125);
for(int i=0;i<NUM_LEDS;i++){
leds[i].setRGB(255,255,255);
FastLED.show();
delay(100);
}
for(int i=0;i<NUM_LEDS;i++){
leds[i].setRGB(0,0,0);
FastLED.show();
delay(100);
}
}
void loop() {
//LIGHTS ON
if (analogRead(A0)>900) {
leds[0] = CRGB::White;
FastLED.show();
}
//LIGHTS OFF
if (analogRead(A0)<200) {
leds[0] = CRGB::Black;
FastLED.show();
}
//BRIGHTS ON
if (analogRead(A1)>900) {
leds[1] = CRGB::White;
FastLED.show();
}
//BRIGHTS OFF
if (analogRead(A1)<200) {
leds[1] = CRGB::Black;
FastLED.show();
}
//HAZARD ON
if (analogRead(A2)>900) {
leds[2] = CRGB::White;
FastLED.show();
}
//HAZARD OFF
if (analogRead(A2)<200) {
leds[2] = CRGB::Black;
FastLED.show();
}
//SEATBELT ON
if (analogRead(A3)>900) {
leds[3] = CRGB::White;
FastLED.show();
}
//SEATBELT OFF
if (analogRead(A3)<200) {
leds[3] = CRGB::Black;
FastLED.show();
}
}