I'm implementing a project on the Arduino. The loop function drives two servo motors using data from analog pins.. and is quite long. I'm also reading data from Serial2, using a bluetooth module paired with an Android phone. Currently, the bluetooth is checked at the start of the loop, but the gap between Serial.available() calls is too long. Can I use an interrupt on the tx2/rx2 pins so the arduino knows to read data from the serial at any point during the loop.
void loop()
{
char recvChar;
if (blueToothSerial.available())
{ //check if there's any data sent from the remote bluetooth shield
recvChar = blueToothSerial.parseInt();
Serial.print(recvChar);
if (recvChar % 2 == 0)
{
Serial.print("east/west: ");
Serial.println(east_west);
Serial.print("north/south: ");
Serial.println(north_south);
Serial.print("rotations: ");
Serial.println(rotations);
}
else {
//do nothing
}
}
//read data from analog pins
//drive servo
}