Ive got Roborealm sending a targets position serially to an Arduino which controls a Sabertooth motor controller. Right now I've only got the targets X screen position being sent and it seems to work fine. I also want to add the targets size (0-160) and send that also, but I'm at a loss on how to separate the 2 variables on the Arduino end. This is what I currently have.
#include <Servo.h> // Include the servo library
Servo myServo; // Create a new servo object
char incomingData[4] = {
0, 0, 0, 0}; // A buffer to store the ASCII value read in from the serial port
int distance = 0; // The distance of the object from the center of the screen
int currentAngle = 90; // The current angle of the servo
int i = 0; // counter
void setup(){
Serial.begin(9600); // Open the serial port with a 9600 baud rate
Serial.println("Serial port ready"); // Print on screen
myServo.attach(9); // Attach the servo signal line to pin 9
myServo.write(currentAngle); // Set the starting angle at 90 degrees
}
void loop(){
// Wait for data to become available at the serial port
if (Serial.available()){
// Get the data coming through the serial port and store it in the buffer
while (i < 4){
incomingData[i] = Serial.read(); // Assign the input value to the incomingData buffer
i++; // Increment the counter
}
distance = atoi(incomingData); // Convert ASCII to Int
Thanks,
Dave