I'm building a project for school. I'm using an old rc boat that i want to control via smart phone. I'm using the android bluetooth rc controller app. So the app is going to my osepp bluetooth board (Arduino BT) which has built in bluetooth. On that board i have a xbee pro shield and a xbee s2. On the boat i have a osepp mega 2560 r3 plus which has adafruit motor shield v2.3, xbee pro shield, and xbee s2. Here is my script so far.
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_MS_PWMServoDriver.h"
#include <SoftwareSerial.h>
Adafruit_MotorShield AFMS = Adafruit_MotorShield();
Adafruit_DCMotor *LeftMotor = AFMS.getMotor(1);
Adafruit_DCMotor *RightMotor = AFMS.getMotor(3);
int state;
void setup() {
Serial.begin(115200); //connect to bt
AFMS.begin();
LeftMotor->setSpeed(150);
LeftMotor->run(FORWARD);
LeftMotor->run(BACKWARD);
LeftMotor->run(RELEASE);
RightMotor->setSpeed(150);
RightMotor->run(FORWARD);
RightMotor->run(BACKWARD);
RightMotor->run(RELEASE);
}
void loop() {
if(Serial.available() > 0){
state = Serial.read();
}
if (state == 'F'){ // Move forward
LeftMotor->run(FORWARD);
RightMotor->run(FORWARD);
}
else if (state == 'B'){ // Move backward
LeftMotor->run(BACKWARD);
RightMotor->run(BACKWARD);
}
else if (state == 'S'){ // Stop
LeftMotor->run(RELEASE);
RightMotor->run(RELEASE);
}
else if (state == 'L'){ // Move left
LeftMotor->run(BACKWARD);
RightMotor->run(FORWARD);
}
else if (state == 'R'){ // Move right
LeftMotor->run(FORWARD);
RightMotor->run(BACKWARD);
}
else if (state == 'G'){ // Move forward left
LeftMotor->run(RELEASE);
RightMotor->run(FORWARD);
}
else if (state == 'I'){ // Move forward right
LeftMotor->run(FORWARD);
RightMotor->run(RELEASE);
}
else if (state == 'H'){ // Move back left
LeftMotor->run(RELEASE);
RightMotor->run(BACKWARD);
}
else if (state == 'J'){ // Move back right
LeftMotor->run(BACKWARD);
RightMotor->run(RELEASE);
}
}
Questions:
-
Does this look right so far?
-
What is the best way to send this with the xbees? AT or API
-
Do i need some kind of xbee library to do this?
I'll just start with these for now. This is my first time really using arduinos and xbees so i'm new to all of this. Thanks for reading and any input is very much appreciated!!!!!!!!!!!