root / trunk / code / projects / linefollowing / main.c @ 1922
History | View | Annotate | Download (1.61 KB)
1 |
#include <dragonfly_lib.h> |
---|---|
2 |
#include <lineFollow.h> |
3 |
|
4 |
|
5 |
|
6 |
int main(void) |
7 |
{ |
8 |
|
9 |
/* initialize components, set wireless channel */
|
10 |
dragonfly_init(ALL_ON); |
11 |
lineFollow_init(); |
12 |
int barCode;
|
13 |
while(1) |
14 |
{ |
15 |
|
16 |
|
17 |
for(int i=0; i<8; i++){ |
18 |
usb_puti(read_line(i)); |
19 |
usb_putc('\t');
|
20 |
} |
21 |
usb_putc(13);
|
22 |
|
23 |
/*
|
24 |
|
25 |
for(int q=0; q<500; q++)
|
26 |
barCode = lineFollow(200);
|
27 |
while(mergeLeft());
|
28 |
for(int q=0; q<1000; q++)lineFollow(200);
|
29 |
|
30 |
continue;
|
31 |
if(barCode==-25)while(turnRight());
|
32 |
continue;
|
33 |
if(barCode != -2 && barCode != LINELOST)
|
34 |
{
|
35 |
usb_puti(barCode);
|
36 |
usb_putc('\n');
|
37 |
}
|
38 |
*/
|
39 |
|
40 |
|
41 |
|
42 |
/*
|
43 |
|
44 |
switch (barCode)
|
45 |
{
|
46 |
|
47 |
|
48 |
case 0: orb_set_color(RED); break;
|
49 |
case 1: orb_set_color(ORANGE); break;
|
50 |
case 2: orb_set_color(YELLOW); break;
|
51 |
case 3: orb_set_color(LIME); break;
|
52 |
case 4: orb_set_color(GREEN); break;
|
53 |
case 5: orb_set_color(CYAN); break;
|
54 |
case 6: orb_set_color(BLUE); break;
|
55 |
case 7: orb_set_color(PINK); break;
|
56 |
case 8: orb_set_color(PURPLE); break;
|
57 |
case 9: orb_set_color(MAGENTA); break;
|
58 |
default: orb_set_color(WHITE); break;
|
59 |
|
60 |
case 0:
|
61 |
straight();
|
62 |
turnRight();
|
63 |
break;
|
64 |
case 2:
|
65 |
straight();
|
66 |
break;
|
67 |
case 3:
|
68 |
straight();
|
69 |
turnLeft();
|
70 |
break;
|
71 |
|
72 |
}
|
73 |
*/
|
74 |
} |
75 |
return 0; |
76 |
} |
77 |
void right()
|
78 |
{ |
79 |
motor_r_set(BACKWARD, 200);
|
80 |
motor_l_set(FORWARD, 200);
|
81 |
delay_ms(400);
|
82 |
} |
83 |
|
84 |
|
85 |
void straight()
|
86 |
{ |
87 |
motor_r_set(FORWARD, 210);
|
88 |
motor_l_set(FORWARD, 210);
|
89 |
delay_ms(200);
|
90 |
move(0,0); |
91 |
delay_ms(2000);
|
92 |
} |
93 |
|
94 |
void left()
|
95 |
{ |
96 |
motor_l_set(BACKWARD, 200);
|
97 |
motor_r_set(FORWARD, 200);
|
98 |
delay_ms(400);
|
99 |
} |