Hi I posted earlier regarding some code that would not work. I have continued to try and understand the issue and the more i dig and tweak the code to understand the issue, the more I think i have isolated it around the checking to see if an LED is lit, by using the code if(leds[5]=CRGB::Black)
I have posted two almost identical sketches below. The first sketch sets led number 5 to blue in void setup and then in void loop it checks to see if that led is blue and if it is it turns it green. This sketch works as expected.
The second sketch set led number 5 to Black in void setup (this turns it off as expected ) and then in void loop if checks to see if the same led is black and if it is, it turns it Green.
This second sketch does not work...the led is turned off (if it was previously on) but doesn't turn green.
Could someone enlighten me???
Sketch 1:
#include <FastLED.h>
#define NUM_LEDS 300
#define DATA_PIN 3
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
leds[5] = CRGB::Blue; //set LED 5 to colour to check for to ensure it is not in some unknow colour
FastLED.show(); //Light LED
delay(5000); //pause to see color
}
void loop() {
if (leds[5] = CRGB::Blue) { //if Blue
leds[5] = CRGB::Green; //Change to Green
FastLED.show();
}
}
Sketch2:
#include <FastLED.h>
#define NUM_LEDS 300
#define DATA_PIN 3
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
leds[5] = CRGB::Black; //set LED 5 to colour to check for to ensure it is not in some unknow colour
FastLED.show(); //Light LED
delay(5000); //pause to see color
}
void loop() {
if (leds[5] = CRGB::Black) { //if Black
leds[5] = CRGB::Green; //Change to Green
FastLED.show();
}
}
I hope this makes sense and thanks for any help