commande robot par bluetooth

// code Arduino

 

#include <SoftwareSerial.h>
#include <Servo.h>
#include <Wire.h>
#include <AFMotor.h>
SoftwareSerial BT(2, 13);
String device;

 

Servo pan;
Servo tilt;
int panposition = 45;
int tiltposition = 90;
AF_DCMotor motor1(1);
AF_DCMotor motor4(4);
#define M1_DEFAULT_SPEED 180
#define M4_DEFAULT_SPEED 180
#define M1_MAX_SPEED 200
#define M4_MAX_SPEED 200
void setup() {
BT.begin(9600);
Serial.begin(9600);
pan.attach(9);
tilt.attach(10);
tilt.write(panposition);
pan.write(tiltposition);
void loop() {
while (BT.available()){
delay(10);
char c = BT.read();
device += c; //build the string.
}
if (device.length() > 0) {
Serial.println(device);
//———–Led1
if(device == « 1 »)
{
motor4.setSpeed(M4_DEFAULT_SPEED);motor4.run(BACKWARD );
motor1.setSpeed(M1_DEFAULT_SPEED);motor1.run(BACKWARD );
}
if(device == « 2 »)
{
motor4.setSpeed(M4_DEFAULT_SPEED);motor4.run(FORWARD );
motor1.setSpeed(M1_DEFAULT_SPEED);motor1.run(FORWARD );

 

}
if(device == « 3 »)
{
motor1.run(RELEASE);
motor4.setSpeed(M4_DEFAULT_SPEED);motor4.run(BACKWARD );
}
if(device == « 4 »)
{
motor4.run(RELEASE);
motor1.setSpeed(M1_DEFAULT_SPEED);motor1.run(BACKWARD );
}
if(device == « 5 »)
{
motor1.run(RELEASE);
motor4.run(RELEASE);
}
if(device == « a »)
{
if (panposition > 0){
panposition = (panposition – 10);
tilt.write(panposition);
Serial.println(panposition);
delay(15);
}
}