root / trunk / code / tools / rangefinders / robot / testIRcycle.c @ 1637
History | View | Annotate | Download (1.33 KB)
1 | 1637 | bneuman | #include <dragonfly_lib.h> |
---|---|---|---|
2 | |||
3 | int main(void) |
||
4 | { |
||
5 | /* initialize components, set wireless channel */
|
||
6 | dragonfly_init(ALL_ON); |
||
7 | |||
8 | //Replace the next two lines with your own code
|
||
9 | //You can add as many lines as you want
|
||
10 | |||
11 | uint8_t rangeNumber[] = {IR1,IR2,IR3,IR4,IR5}; //0 indexed
|
||
12 | uint8_t cIndex; |
||
13 | |||
14 | //initial setup (IR1)
|
||
15 | cIndex=0;
|
||
16 | orb1_set_color(BLUE); |
||
17 | orb2_set_color(GREEN); |
||
18 | |||
19 | while(1) { |
||
20 | |||
21 | usb_puti(range_read_distance(rangeNumber[cIndex])); |
||
22 | usb_putc('\r');
|
||
23 | |||
24 | if (button1_click()) {
|
||
25 | switch (cIndex){ //button1 chooses a color channel |
||
26 | case 0: //IR1 |
||
27 | orb1_set_color(RED); |
||
28 | orb2_set_color(RED); |
||
29 | cIndex=1;
|
||
30 | break;
|
||
31 | case 1: //IR2 |
||
32 | |||
33 | orb1_set_color(GREEN); |
||
34 | orb2_set_color(GREEN); |
||
35 | cIndex=2;
|
||
36 | break;
|
||
37 | case 2: //IR3 |
||
38 | |||
39 | orb1_set_color(BLUE); |
||
40 | orb2_set_color(BLUE); |
||
41 | cIndex=3;
|
||
42 | break;
|
||
43 | case 3: //IR4 |
||
44 | orb1_set_color(YELLOW); |
||
45 | orb2_set_color(YELLOW); |
||
46 | cIndex=4;
|
||
47 | break;
|
||
48 | case 4: //IR5 |
||
49 | orb1_set_color(BLUE); |
||
50 | orb2_set_color(GREEN); |
||
51 | cIndex=0;
|
||
52 | break;
|
||
53 | default: //undefined |
||
54 | return 0; |
||
55 | break;
|
||
56 | } |
||
57 | delay_ms(50); //allows button press to release |
||
58 | } |
||
59 | delay_ms(50); //refresh frequency: 1000/(50ms) refresh rate |
||
60 | |||
61 | } |
||
62 | |||
63 | |||
64 | |||
65 | //this tell the robot to just chill out forever. don't put anything after this
|
||
66 | while(1); |
||
67 | return 0; |
||
68 | } |