Hello,
I'm working on a project which requires me to switch on only particular LEDs via Bluetooth using an app, for this to work as I want it to the LEDs need to be turned off at the start and only switch on when a particular input is received from the app.
When I connect my phone to the Bluetooth and press the respective buttons responsible for sending data to the Arduino the LEDs do not respond to the data received
Here is my code
#include <FastLED.h>
#define NUM_LEDS 5 //no of leds
#define DATA_PIN 7
#define BRIGHTNESS 90
//#define ledPin 7 //pin to which led is connected on arduino
int state = 0; //variable to store data coming from phone
CRGB leds[NUM_LEDS];
void setup()
{
FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS); //setup led strip
pinMode(DATA_PIN, OUTPUT); //set led pin as op for bluetooth
//digitalWrite(ledPin, LOW); //setting op as low
Serial.begin(38400); // Default communication rate of the Bluetooth module
FastLED.setBrightness(BRIGHTNESS);
/*for(int i=0;i<NUM_LEDS;i++)
{
leds[i] = CRGB::Black;
FastLED.show();
}*/
}
void loop()
{
if(Serial.available() > 0) // Checks whether data is comming from the serial port
{
state = Serial.read(); // Reads the data from the serial port
if(state=='1')
{
leds[0] = CRGB::Red;
FastLED.show();
}
if(state=='2')
{
leds[1] = CRGB::Red;
FastLED.show();
}
if(state=='3')
{
leds[2] = CRGB::Red;
FastLED.show();
}
if(state=='4')
{
leds[3] = CRGB::Red;
FastLED.show();
}
if(state=='5')
{
leds[4] = CRGB::Red;
FastLED.show();
}
}
}