Pages: 1 2 [3]   Go Down
Author Topic: More MATLAB Trouble  (Read 1575 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 26
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
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]
Logged

Pages: 1 2 [3]   Go Up
Jump to: