diff --git a/BluetoothControlTank.ino b/BluetoothControlTank.ino index 3201eba..580c9d8 100644 --- a/BluetoothControlTank.ino +++ b/BluetoothControlTank.ino @@ -4,9 +4,13 @@ 5=move forward left, 6=move forward right 7=move backward left, 8=move backward right */ +#include enum { pinLB = 12, pinLF = 3, pinRB = 13, pinRF = 11 }; +int delay_time = 300; int direct = 0; +Servo myservo; + void setup() { Serial.begin(9600); // define pin for motor output @@ -14,6 +18,8 @@ void setup() pinMode(pinLF, OUTPUT); // pin 3 (PWM) pinMode(pinRB, OUTPUT); // pin 13 pinMode(pinRF, OUTPUT); // pin 11 (PWM) + myservo.attach(9); // Define servo motor output pin to D9 (PWM) + handshake(); } void loop() @@ -63,44 +69,56 @@ void backward() void turn_right() { set(LOW, HIGH, 255, 255); - delay(300); + delay(delay_time); stopp(); } void turn_left() { set(HIGH, LOW, 255, 255); - delay(300); + delay(delay_time); stopp(); } void backward_left() { set(HIGH, LOW, 255, 0); - delay(300); + delay(delay_time); stopp(); } void backward_right() { set(LOW, HIGH, 0, 255); - delay(300); + delay(delay_time); stopp(); } void forward_left() { set(LOW, HIGH, 255, 0); - delay(300); + myservo.write(45); + delay(delay_time); if (direct == 1) forward(); else stopp(); + myservo.write(90); } void forward_right() { set(HIGH, LOW, 0, 255); - delay(300); + myservo.write(180-45); + delay(delay_time); if (direct == 1) forward(); else stopp(); + myservo.write(90); +} +void handshake() +{ + myservo.write(0); + delay(delay_time); + myservo.write(180); + delay(delay_time); + myservo.write(90); }