Ebtehal___
Ebtehal___

Reputation: 131

send pin number and pin value from android to arduino kit via bluetooth

what i want is sending 3 pins numbers and values from my android to arduino kit via bluetooth in a single write command

i tried to pass them separated by commas and parsing them ParseFloat() but i don;t know clearly how this function works

if i send (12,4.6),(13,3.2),(14,2)

x=Serial.parseFloat();
y=Serial.parseFloat();
z=Serial.parseFloat();

x=12 , y = 4.6 , z = 13 ;

that's Right?

i want to know the best format to send them to arduino and how to parse in arduino code

thanks

Upvotes: 0

Views: 272

Answers (1)

Jeepx
Jeepx

Reputation: 51

From http://arduino.cc/en/Serial/ParseFloat : Serial.parseFloat() returns the first valid floating point number from the Serial buffer. Meaning to the parser, for x, 12 is the first valid floating point number.

So the output is expected since floating point values will be in the form :

123.456

So to get back to your problem : You can use the parseFloat to get the pin number. However to get the value, you should first get the string that only contains the value. To do this you can use the function indexOf to find the location of the "," in your string and get the substring that starts after it with the substring function .

Upvotes: 1

Related Questions