Go Down

Topic: More MATLAB Trouble (Read 1 time) previous topic - next topic

fayadAli

Thank you Paul really thanks for all the guidance you provided
thanks to this forum its really helpful.
I got it with my new algorithm I will post my code for any one who get stuck
I am sending with 3 different delimiter values
the sent data as a string is: "servo,pwm;pressure:\n"

Code: [Select]

char servo[15], pwm[15], pressure[15];
char inData[15];
int i =0;
float servoFloat = 0;
float pwmFloat = 0;
float pressureFloat =0;
void setup ()
{
  Serial.begin(9600);
  inData[0] = '/0';

  servo[0] = '\0';
  pwm[0] = '\0';
  pressure[0] = '\0';
}
//****************************************************************************************************************end of setup

void loop()
{

  int x = 0;
  while((Serial.available() > 0) && (x== 0)) 
  {
    char aChar = Serial.read();

    switch (aChar){
    case ',':
        servoFloat =atof(inData);
      inData[0] = '\0';
      i =0;
      break;
    case ';':
      pwmFloat = atof(inData);
      inData[0] = '\0';
      i =0;
      break;
    case ':':
   
      pressureFloat = atof(inData);
      inData[0] ='\0';
      i = 0;
      break;
    case'\n':
      x=1;
      break;

    default: 
      inData[i++] = aChar; // Add the char to the array
    }

  }


  if(x == 1)
  {
    Serial.print("I passed here: ");
    Serial.println();
    Serial.print(servoFloat);
    Serial.println();
    Serial.print(pwmFloat);
    Serial.println();
    Serial.print(pressureFloat);
    Serial.println();
  } 



}

[\code]

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy