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
 

Quick Reply

With Quick-Reply you can write a post when viewing a topic without loading a new page. You can still use bulletin board code and smileys as you would in a normal post.

Warning: this topic has not been posted in for at least 120 days.
Unless you're sure you want to reply, please consider starting a new topic.

Note: this post will not display until it's been approved by a moderator.
Name:
Email:

shortcuts: alt+s submit/post or alt+p preview