-
Notifications
You must be signed in to change notification settings - Fork 16
/
Human_tracker_arduino.ino
122 lines (110 loc) · 1.97 KB
/
Human_tracker_arduino.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
/*
@authors:
Yash Chandak Ankit Dhall
*/
//Define pin numbers
//right motor
int m1f = 10;
int m1r = 9;
//left motor
int m2f = 6;
int m2r = 5;
int led = 13;
char value;
int val[3];
int len;
int direc;
void setup()
{
//start serial communication at Baud rate of 9600
Serial.begin(9600);
pinMode(m1f, OUTPUT);
pinMode(m1r, OUTPUT);
pinMode(m2f, OUTPUT);
pinMode(m2r, OUTPUT);
pinMode(led, OUTPUT);
digitalWrite(led, HIGH);
}
void execute()
{
int no;
int i = 0;
//convert ASCII value from serial buffer into int
no = value - '0';
//Serial.println(no);
int a, b, c, d;
/*
"""
Direction control Index:
'<' , '>' are the frame check bits for serial communication
Numbers represent the direction to be moved as per their position on numpad
1: Back Left
2: Back
3: Back right
4: Left
5: Stay still
6: Right
7: Front Left
8: Forward
9: Forward right
"""
*/
switch (no)
{
case 0:
a = 0; b = 100; c = 100; d = 0;
break;
case 3:
a = 0; b = 255; c = 0; d = 100;
break;
case 2:
a = 0; b = 255; c = 0; d = 255;
break;
case 1:
a = 0; b = 100; c = 0; d = 255;
break;
case 4:
a = 255; b = 0; c = 0; d = 0;
break;
case 5:
a = 0; b = 0; c = 0; d = 0;
break;
case 6:
a = 0; b = 0; c = 255; d = 0;
break;
case 7:
a = 255; b = 0; c = 100; d = 0;
break;
case 8:
a = 150; b = 0; c = 150; d = 0;
break;
case 9:
a = 100; b = 0; c = 255; d = 0;
break;
}
analogWrite(m1f, a);
analogWrite(m1r, b);
analogWrite(m2f, c);
analogWrite(m2r, d);
//delay(255);
}
void loop()
{
if (Serial.available())
{
//Check for frame control bits
char ch = Serial.read();
if (ch == '<')
{
len = 0;
}
else if (ch == '>')
{
execute();
//Serial.println(value);
len = 1;
}
else if (len == 0)
value = ch;
}
}