SoftwareSerial BTSerial(10, 11); // RX, TX
int pp; //temp value
AF_DCMotor motor(1,MOTOR12_2KHZ);
Servo servo;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
BTSerial.begin(9600); //BTSerial 9600,19200,38400,57600
servo.attach(SERVO1_PWM);
motor.run(RELEASE);
}
void loop() {
// put your main code here, to run repeatedly:
if (BTSerial.available()>0){
pp=BTSerial.read();
Serial.println(pp);
switch(pp){
case 'f': //Forward
Up();
break;
case 'b': //Back
Down();
break;
case 'l': //Turn Left
Left();
break;
case 'r': //Turn Right
Right();
break;
case 's': //Stop
stop();
break;
}
}
}
int Up(){
servo.write(0);
motor.setSpeed(200);
motor.run(FORWARD);
//delay(1000);
}
int Down(){
servo.write(0);
motor.setSpeed(200);
motor.run(BACKWARD);
}
int Right(){
servo.write(45);
}
int Left(){
servo.write(135);
}
int stop(){
motor.run(RELEASE);
}
===============================
程式結束