-
Notifications
You must be signed in to change notification settings - Fork 1
/
BluetoothControlTank.ino
80 lines (74 loc) · 1.62 KB
/
BluetoothControlTank.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/*
L=Left, R=Right, F=Forward, B=Back
*/
int pinLB = 12; // define pin 12
int pinLF = 3; // define pin 3
int pinRB = 13; // define pin 13
int pinRF = 11; // define pin 11
int val;
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)
}
void advance() // move forward
{
digitalWrite(pinLB, LOW); // right wheel moves forward
digitalWrite(pinRB, LOW); // left wheel moves forward
analogWrite(pinLF, 255);
analogWrite(pinRF, 255);
}
void stopp() // stop
{
digitalWrite(pinLB, HIGH);
digitalWrite(pinRB, HIGH);
analogWrite(pinLF, 0);
analogWrite(pinRF, 0);
}
void right() // turn right (single wheel)
{
digitalWrite(pinLB, LOW); // left wheel moves forward
digitalWrite(pinRB, HIGH); // right wheel moves backward
analogWrite(pinLF, 255);
analogWrite(pinRF, 255);
}
void left() // turn left (single wheel)
{
digitalWrite(pinLB, HIGH); // left wheel moves forward
digitalWrite(pinRB, LOW); // right wheel moves backward
analogWrite(pinLF, 255);
analogWrite(pinRF, 255);
}
void back() // move backward
{
digitalWrite(pinLB, HIGH); // motor moves to left rear
digitalWrite(pinRB, HIGH); // motor moves to right rear
analogWrite(pinLF, 255);
analogWrite(pinRF, 255);
}
void loop()
{
val = Serial.read();
if (val == 'f') {
advance();
}
if (val == 'b') {
back();
}
if (val == 'l') {
left();
delay(600);
stopp();
}
if (val == 'r') {
right();
delay(600);
stopp();
}
if ( val == 's') {
stopp();
}
}