I gave up on that and I am using
This one it works fine and I am able to receive and separate the values. all I need to now is how to pass the float values to the void loop
I am trying to put them in a float array and return that but I couldn't
[code]
float servoInt = 0;
float pwmInt = 0;
float pressureInt =0;
void setup ()
{
Serial.begin(9600);
}
void process_data (char * data)
{
Serial.println();
Serial.println (data);
delay(1000);
}
void parse_data(char * data)
{
int s = 1;
int j = 0;
char value[15];
for(int k =0 ; k<15;k++){
value[k]=0;
}
String servo;
String pwm;
String pressure;
for(int i = 0; i <100;i++)
{
if(data[i] == ',')
{
switch(s){
case 1:
servo = value;
servoInt = atof(value);
Serial.print("servoInt is:");
Serial.print(servoInt);
for(int k =0 ; k<15;k++){
value[k]=0;
}
s = 2;
break;
case 2:
pwmInt = atof(value);
Serial.print(" the actuator angle received in float is ");
Serial.print(pwmInt);
pwm = value;
for(int k =0 ; k<15;k++){
value[k]=0;
}
s = 3;
break;
case 3:
pressureInt = atof(value);
pressure = value;
for(int k =0 ; k<15;k++){
value[k]=0;
}
s= 4;
break;
}
j = 0;
}
else{
value[j] = data[i];
j++;
}
}
Serial.println("I got the final values");
Serial.println();
Serial.print("Servo Angle:");
Serial.print(servoInt);
Serial.println();
Serial.print(" the actuator angle received in float is: ");
Serial.print(pwmInt);
Serial.println();
Serial.print("the presssure received:");
Serial.print(pressureInt);
delay(1000);
}
void loop()
{
int i= 0;
static char input_line [50];
char datas[10];
static unsigned int input_pos = 0;
if (Serial.available () > 0)
{
char inByte = Serial.read ();
switch (inByte)
{
case '\n':
input_line [input_pos] = 0;
process_data (input_line);
parse_data(input_line);
input_pos = 0;
break;
case '\r':
break;
default:
if (input_pos < (50))
input_line [input_pos++] = inByte;
break;
} // end of switch
}
}
[\code]
[/code]