Hello there everyone. So I’ve been working on a project involving lighting up WS2812Bs via Bluetooth.The project is somewhat working the way I want it to, but there is a problem. I can light my LEDs up then turn it off, but the code for turning it off is being looped forever, so I cannot turn on my LEDs again once I’ve turned it off. I would like to know where in my code I should enter the break function to make sure I can turn the LEDs on again after I’ve turned it off. The following would be my code.
#include <SoftwareSerial.h>
#include "FastLED.h"
SoftwareSerial BT(10, 11);
#define DATA_PIN 2
#define NUM_LEDS 8
CRGB leds[NUM_LEDS];
bool off = false;
bool book1 = false;
void setup() {
BT.begin(9600);
BT.println("Hello from Arduino");
FastLED.show();
FastLED.addLeds<WS2812B, DATA_PIN>(leds, NUM_LEDS);
}
void loop()
{
if(BT.available() > 0)
{
char c = BT.read();
if(c == 'o')
off = true;
}
if(off)
{
OFF();
}
if(BT.available() > 0)
{
char c = BT.read();
if(c == '1')
book1 = true;
}
if(book1)
{
Book1Indicator();
}
void OFF() {
leds[NUM_LEDS] = CRGB(0,0,0);
FastLED.show();
}
void Book1Indicator() {
leds[0] = CRGB(0,0,255);
FastLED.show();
delay(150);
leds[7] = CRGB(255,255,255);
FastLED.show();
delay(150);
leds[6] = CRGB(255,255,255);
FastLED.show();
delay(250);
leds[5] = CRGB(255,255,255);
FastLED.show();
delay(150);
leds[4] = CRGB(255,255,255);
FastLED.show();
delay(150);
leds[3] = CRGB(255,255,255);
FastLED.show();
delay(150);
leds[2] = CRGB(255,255,255);
FastLED.show();
delay(150);
leds[1] = CRGB(255,255,255);
FastLED.show();
delay(150);
FastLED.clear();
delay(200);
}
}
It’d be really helpful if someone could point out where I should insert the break code or whatever additional or modified code in order to be able to turn on the LEDs again after turning them off. Finally, thank you to everyone to taking the time to read this and lend a hand.