Skip to content

Commit

Permalink
Servo added
Browse files Browse the repository at this point in the history
  • Loading branch information
vomikan committed Jun 13, 2017
1 parent e3e0c60 commit 1890223
Showing 1 changed file with 24 additions and 6 deletions.
30 changes: 24 additions & 6 deletions BluetoothControlTank.ino
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,22 @@
5=move forward left, 6=move forward right
7=move backward left, 8=move backward right
*/
#include <Servo.h>
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
pinMode(pinLB, OUTPUT); // pin 12
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()
Expand Down Expand Up @@ -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);
}

0 comments on commit 1890223

Please sign in to comment.