-
Notifications
You must be signed in to change notification settings - Fork 0
/
Car_Aruco-checkpoint1.ino
148 lines (111 loc) · 2.74 KB
/
Car_Aruco-checkpoint1.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
const int IN1 = 9; //Change direction
const int IN2 = 8; //Change direction
const int IN3 = 7; //Motors on and off
const int IN4 = 6;
const int EN = 10; //const int lights = 13;
//const int horn = 8;
int pwm = 75;
char command = 'E';
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 bits per second:
//Set pins as outputs
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
pinMode(EN, OUTPUT);
//pinMode(lights, OUTPUT);
//pinMode(horn, OUTPUT);
//void stop();
//digitalWrite(lights, LOW);
// digitalWrite(horn, LOW);
}
void Stop()
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
}
void Front()
{
//This function will turn Motors front.
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void Back()
{
//This function will turn Motors backward.
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
void Left()
{
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
}
void Right()
{
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
}
/*void Lights()
{
if (digitalRead(lights)==LOW)
digitalWrite(lights,HIGH);
else
digitalWrite(lights,LOW);
}
void Horn()
{
int i;
//for(i = 0; i < 4 ; i++)
{
digitalWrite(horn,HIGH);
delay(200);
digitalWrite(horn,LOW);
delay(200);
if(i=1)
delay(400);
}
}
/*
void turbo()
{
if (speed == 200)
speed = 255;
else
speed = 200;
}
*/
void loop() {
//delay(500);
//recieve bluetooth signal
if(Serial.available() > 0) // Send data only when you receive data:
{
command = Serial.read(); //Read the incoming data & store into data
Serial.print(command);
}
analogWrite(EN, pwm);
if (command == 108)
{
Left();
}
else if (command == 114)
{
Right();
}
else if (command == 120)
{
Front();
}
command = ' ';
}