3 years, 5 months ago.

Reading multiple strings from serial port

Hi everyone!

I am reading mulitple strings from the serial port like this:

-150, 45

-45, 90

99, -234

34, -80

and I am trying to separate on mbed to control a dc motor, but before that I want to be sure that I am reading the two strings correctly, this is my code:

  1. include "mbed.h"

PwmOut ledverde(LED1); PwmOut ledrojo(LED2);

Serial pc(USBTX, USBRX);

int main() {

while(1) { int xmano, xdedo; pc.scanf("%d,%d", &xmano,&xdedo); pc.printf("xmano: %d\n", &xmano); pc.printf("xdedo: %d\n", xdedo); if (xmano>=0){ledverde = 0;} if (xmano<0){ledverde = 1;} if (xdedo>=0){ledrojo = 0;} if (xdedo<0){ledrojo = 1;}

} }

I do not if it is not possible to read like this way, but does someone know how do it?

Comment on this question
Be the first to answer this question.

You need to log in to post a question