forked from helium876/BoeBot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbot.c
More file actions
146 lines (116 loc) · 2.54 KB
/
Copy pathbot.c
File metadata and controls
146 lines (116 loc) · 2.54 KB
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
#include <Servo.h>
Servo right;
Servo left;
//**************************************//
// Declaration of the IRF PINs //
//**************************************//
#define IRL_PIN_s0 4//22
#define IRL_PIN_s1 5//23
#define IRL_PIN_s2 6//24
#define IRL_PIN_s3 7//25
#define IRL_PIN_s4 8//26
#define IRL_PIN_s5 9//27
#define IRL_PIN_s6 10//28
#define IRL_PIN_s7 11//29
void setup(){
Serial.begin(9600); //Opens serial connection at 9600 baud rate
right.attach(2);
left.attach(3);
left.write(90);
right.write(90);
}
int IRL_in;
// declaration of the buffer to store the output of all s0- s7 pins of the KRF
void loop()
{
IRL_Read();
switch(IRL_in)
{
case 0b11111111: //off the line
break;
case 0b00000000: /// in a box
break;
case 0b11000011:
//case 0b11000111:
//case 0b11100011:
//case 0b10000001: //forward
forward();
break;
case 0b11110001:
case 0b11100001:
case 0b11110000:
case 0b11111000:
case 0b11111100:
case 0b11111110: //right curve
rightcurve();
break;
case 0b10000000:
case 0b11000000:
case 0b11100000:
//do{
rightturn();
delay(200);
IRL_Read();
//}while(IRL_in != 0b11110000);
break;
case 0b00000001:
case 0b00000011:
case 0b00000111:
case 0b00001111:
//do{
leftturn();
delay(200);
IRL_Read();
//}while(IRL_in != 0b00001111);
break;
case 0b10000111:
case 0b00011111:
case 0b00111111:
case 0b01111111: //right curve
leftcurve();
break;
//default:
//forward();
// break;
}
}
void stop(){
right.write(90);
left.write(90);
}
void forward(){
right.write(0);//Move forward
left.write(180);//Move forward
}
void rightcurve(){
Serial.println("Right Curve");
right.write(130);//180
left.write(180);//90
}
void rightturn(){
Serial.println("Right Turn");
//right.write(90);
//left.write(90);
right.write(180);
left.write(180);
}
void leftcurve(){
Serial.println("Left Curve");
right.write(0);
left.write(45);
}
void leftturn(){
Serial.println("Left Turn");
//right.write(90);
//left.write(90);
right.write(0);
left.write(0);
}
void IRL_Read()
{
IRL_in = 0;
for(int i = 0; i <= 7; i++){
IRL_in = (IRL_in << 1) + digitalRead(IRL_PIN_s7 - i);
}
Serial.println(IRL_in, BIN);
}