Hi, this is my code for the Android that sends the Data
public void writeData(String data)
{
try
{
outStream = btSocket.getOutputStream();
}
catch(IOException e)
{
Log.d("silentcoder", "[BEFORE] could not send data");
}
String message = data;
byte[] msgBuffer = message.getBytes();
try
{
outStream.write(msgBuffer);
}
catch(IOException e)
{
Log.d("silentcoder", "could not send data", e);
}
}
Here is how i send the servo data using the method
writeData(data + "\n");
Here is how i receive the data in Arduino
void loop()
{
// if there's any serial available, read it:
while (Serial.available() > 0) {
// look for the next valid integer in the incoming serial stream:
motor = Serial.parseInt();
// do it again:
pos = Serial.parseInt();
// look for the newline. That's the end of your sentence:
if (Serial.read() == '\n') {
myservo.write(pos); // tell servo to go to position in variable 'pos'
delay(15); // waits 15ms for the servo to reach the position
}
}
}
Is there any efficient way to send/receive the data?
Thanks