I have 2 questions related to each other, well at least in my case -
How can I read the status of an LED to check of it is ON or OFF, or may be Black or White?
How can I put 2 or 3 conditions using if else if to read the status of LEDs and execute the code accordingly?
For example -
if LED 1 is ON and LED 10 is ON, do something
if LED 1 is ON and LED 10 is OFF, do something else
if LED 1 is OFF and LED 10 is OFF, do nothing
I am trying the code below but no luck.
#include <FastLED.h>
#define NUM_LEDS 60
#define DATA_PIN 12
CRGB leds[NUM_LEDS];
const CRGB Test_Color = CRGB::White;
Void setup() {
FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
FastLED.clear();
FastLED.show();
void buttonThree() {
Serial.println("Button 3 has been pressed");
if (leds[10] == Test_Color && leds[30] == Test_Color){
for (int k = 40, j = NUM_LEDS-40; k < NUM_LEDS- 40, j > 0 ; j--, k++){ // Lights_ON from 2/3
for(int whiteLed = 0; whiteLed < NUM_LEDS-k; whiteLed = whiteLed + 1) { // Move a single led
leds[whiteLed] = CRGB::White; // Turn our current led on to white, then show the leds
FastLED.show(); // Show the leds (only one of which is set to white, from above)
delay(10); // Wait a little bit
if ( whiteLed != j-1){ // Turn our current led back to black for the next loop around
leds[whiteLed] = CRGB::Black;
}}}}
else if {
do stuff
}
}
Oh wow! why didn't I think about that. Thanks Brattain Member for your reply to a Newbie.
The problem is that I know when it is ON but Arduino can't see unfortunately, at least mine can't.
So like I explained in my original post, I want to get the ON/OFF status of LEDs after last code execution and based on that, decide which set of code to run when a button is pressed. If you need more information, here you go -
4 button for 4 light presets which are -
1/3 of total LEDs ON
2/3 of total LEDs ON
All LEDs ON
All LEDs OFF
To explain further for better understanding, there are different set of codes for going to preset 1 from preset 2,3 and 4
These LEDs have an associated variable array element number.
Let's say a Neo-Pixel array element (example leds[20]) has the value 0xFFFFFF.
This element can be read by your code; when it reads the RGB value, it finds red is FF green is FF and blue is FF.
If array element was 0x000000 this would mean the red green and blue LEDs are turned off.
I am trying to do something like this in my code. I defined White as a test color and check for true/false values using the code below. But can't figure out why it is not working.
if (leds[10] == Test_Color && leds[30] == Test_Color){
code goes here
}
My question is, what am I doing wrong here.
BTW
Thank you for your sarcastic comments.
It realized it was totally uncalled for. My sincere apologies.