I made a simple mobile application to send LED_ON or LED_OFF when a button is clicked. In the below code the while loop is not fully completed while execution but the controller is going to the void loop() and continuing from there.
char command;
String my_final="LED_OFF";
#define led 9
void setup(){
Serial.begin(9600);
pinMode(led, OUTPUT);
Serial.println("ready");
}
void loop(){
if(Serial.available() > 0){
my_final = "";
while(Serial.available() > 0){
command = (byte)Serial.read();
my_final += command;
Serial.println("test");
}
Serial.println(my_final);
}
if(my_final == "LED_ON"){
Serial.println(my_final);
analogWrite(led, 255);
my_final == "LED_ON";
}
if(my_final == "LED_OFF"){
Serial.println(my_final);
analogWrite(led, 0);
my_final == "LED_OFF";
}
}
The main problem happens in my_final=""
as i have to do this to accept new input from the bluetooth. i just cant seem to find a way around this problem.
EDIT
This is what im getting in the serial monitor. test L test E test D test _ test O test N
.