If Else loop to receive Boolean

I am trying to write a program for ws2811 LEDs. I'm just looking for guidance in the right direction; I have a basic understanding of Arduino and FastLED.

Right now, the startup works. I don't know how to go about receiving the boolean data and then how to set up the if-else statement. I want the program to keep the LEDs one color when receiving 'true' and then blink when it receives a 'false' input. In short, I'm trying to get the LEDs to blink if my Arduino disconnects from Bluetooth.

#define DATA_PIN     3
#define NUM_LEDS    50
#define BRIGHTNESS  64
#define LED_TYPE    WS2811
#define COLOR_ORDER BRG
CRGB leds[NUM_LEDS];
#define NUM_BLINK 5    //blink 5 times

void setup()
{
  Serial.begin(9600);
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);

  //blink when turned on
  for (int i = 0; i < NUM_BLINK; i++)
  {
    blink1();
  }

  //then stay solid color
  fill_solid(leds, NUM_LEDS, CRGB::Green); //go blue after blinking
  FastLED.show();

}//end setup


// receieve boolean value from other code
void connectedLED (bool connectedSTATUS)
{

  //if value is true - stay on
  if (connectedSTATUS == true)
  {
    //led strip stay on solid
    fill_solid(leds, NUM_LEDS, CRGB::Green);
    FastLED.show();
  }

  //else value is false - blink
  else (connectedSTATUS == false);
  {
    //led strip blink
    blink1();
  }//end else

}//end void connectedLED


//blink function
void blink1()
{
  for (int dot = 0; dot < NUM_BLINK; dot++)
  {
    fill_solid(leds, NUM_LEDS, CRGB::Blue);
    FastLED.show();
    delay(200);
    fill_solid(leds, NUM_LEDS, CRGB::Black);
    FastLED.show();
    delay(200);
  }
}//end blink1

void loop() {
 //I am sure that 'connectedLED' should go in 'loop'just not sure how
}//end loop

Your else doesn't need an expression .
If a Boolean isn't true, then you know it is false

Also, your syntax for the 'else' is completely wrong.

  else (connectedSTATUS == false); // 'if' is missing and ';' incorrectly terminates the statement

should be

  else if (connectedSTATUS == false)

or just

  else

as mentioned above.

Others have already pointed out your syntax issues but I'm wondering what else is the Arduino going to be doing?

Any time you use a delay() call you will block anything else from happening. In this case if the Arduino is disconnected from BlueTooth (as you say) and the LEDs are blinking 5 times every loop() call then you can only do other processing every 2 seconds.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.