Hello. I have a problem with my led strip code. I want it to be controlled with bluetooth. But I cannot figure out that whats wrong with my code. I enclose the code. Thank you.
#include "FastLED.h"
#define DATA_PIN 10
#define CHIPSET WS2812
#define NUM_LEDS 30
struct CRGB leds[NUM_LEDS];
int myleds_white1 [] = {0, 1, 2, 3, 45, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int myleds_black1 [] = {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
int myleds_red [] = {16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30};
int myleds_black2 [] = {0, 1, 2, 3, 45, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15};
int myleds_full [] = {0, 1, 2, 3, 45, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
};
char data;
void setup() {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
FastLED.setBrightness(100);
FastLED.clear();
Serial.begin(9600);
}
void loop() {
data = read_bluetooth();
Serial.println(data);
if (data != '@') {
switch (data) {
case '7':
ledstrip_on_full(); //all leds on
break;
case '8':
ledstrip_off(); //all leds off
break;
case '9':
ledstrip_on_white(); // white
break;
case 'a':
ledstrip_on_red(); //red
break;
case 'b':
ledstrip_off(); //off
break;
}
}
void ledstrip_on_full() { //all leds on
for (int i = 0; i < 30; i++)
{
leds[myleds_full[i] ] = CRGB::White //all 30 leds on ligthing white
}
FastLED.show();
delay (15);
}
if (read_bluetooth() == 'b') {
ledstrip_off();
break;
}
void ledstrip_on_red() { //red on
for (int i = 0; i = 30; i++) {
leds[myleds_black2[i] ] = CRGB::Black; //0-15 leds off
leds[ myleds_red[i] ] = CRGB::Red; //16-30leds on
FastLED.show();
delay(150);
}
if (read_bluetooth() == 'b') {
ledstrip_off();
break;
}
}
void ledstrip_on_white //white on
for (int i = 0; i <= 30; i++) {
leds[myleds_black1[i] ] = CRGB::Black; //first 15 black
leds[ myleds_white1[i] ] = CRGB::White; //16-30 leds turn off white
FastLED.show();
delay(150);
}
ledstrip_off();
}
void ledstrip_off() {
for (int i = 0; i <= 30; i++) {
leds[i] = CRGB::Black; //all leds OFF
FastLED.show();
}
}
char read_bluetooth() {
char msg;
if (Serial.available()) {
msg = Serial.read();
} else msg = '@';
return msg;
}