How split Word and Number received from Serial Minitor


hi,

i'm send command , value via serial monitor format "mystring nn.nn", how can split these data 2 variables?

example:

data send via serial monitor - drink 25.00

data received split 2 variables
myitem = drink
mymoney = 25.00

thanks.

code: [select]
const char example[] =  "try 23.44";

void setup() {
  serial.begin(250000);
  char buff[20] = "";
  int val1 = 0;
  int val2 = 0;
  byte count = sscanf(example, "%s %d.%d", buff, &val1, &val2);
  if (count == 3) {
    int iamount = val1 * 100 + val2;
    float famount = val1 + val2 / 100.0;
    serial.print(f("succsessfully parsed '"));
    serial.print(buff);
    serial.print(f("' ints "));
    serial.print(val1);
    serial.print(f(" , "));
    serial.print(val2);
    serial.print(f(", int "));
    serial.print(iamount);
    serial.print(f(", float "));
    serial.print(famount);
  }
}
void loop() {}
code: [select]
succsessfully parsed 'try' ints 23 , 44, int 2344, float 23.44


Arduino Forum > Using Arduino > Programming Questions > How split Word and Number received from Serial Minitor


arduino

Comments

Popular posts from this blog

Help needed for choosing soldering station

Error Message when accessing Adobe

Fuelino for Arduino Nano - motorcycle Fuel Injection control and data logger