How to send an ASCII 'SPD10.2' and have it change the variable 'SPD' to 10.2?


I have several variables in my program that i want to be able to change without having to edit the sketch and then re-upload to my Arduino Nano every time. I have declared 2 variables outside of the void setup() and void loop() loops, so my understanding is that these 2 variables are global variables, but i want to be able to change each of their value by using an Android app that can send ASCII values via Bluetooth to the robot.

So, i want to get some advice on how to approach this problem. My idea is that i need to first be able to split the incoming data, for example, 'SPD10.2' into two parts, the combined characters 'SPD' and the float value of '10.2' and then have an IF statement which checks that only those letters are typed and valid for the value of the variable SPD in my program to change from whatever global variable value to its new value of 10.2. For this to work, should i change the global variables to inside the setup loop instead??

//global variables
float SPD = 7.9;
float BRI = 20.3;
char newdata;

//void loop()
//if the first characters are SPD, then changes value of variable SPD 
//I have no idea how to go about this.
 if(newdata == 'SPD')     {    
    (SPD = 10.2); 
     Serial.println("Changed speed to %f", SPD);

That looks all okey to me. Just remember that a restart if the cintroller calls for data changed again.

The serial input basics tutorial has information that you could use to make a packet containing your data, receiving and parsing the packet.

 if(newdata == 'SPD')

Single quotes are for single characters. Post a picture of your keyboard with the SPD key circled, please.


A bunch of library files for all sorts of stuff.