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
|
// prototype code for a line follower bot. Uses a very simple for loop
// to check two top-hat reflectance sensors aligned on left and right of
// the line, presumably a black tape. The #defines will have to be adjusted.
// Written THU MAY 3 2007 02:40
#define L_MOTOR 0
#define R_MOTOR 3
#define HAT_L analog(4)
#define HAT_R analog(5)
#define HAT_THRESH 135
#define V_FWD 75
void fwd(){ mav(L_MOTOR,V_FWD); mav(R_MOTOR,V_FWD); }
void left(){ mav(L_MOTOR,0); mav(R_MOTOR,V_FWD); }
void right(){ mav(L_MOTOR,V_FWD); mav(R_MOTOR,0); }
int main()
{
for(;;)
{
if(HAT_L >= THRESH && HAT_R >= THRESH) fwd();
if(HAT_L < THRESH) /* uhoh, drifted left! */ right();
if(HAT_R < THRESH) /* uhoh, drifted right! */ left();
}
return 0;
}
|