Project

General

Profile

Statistics
| Revision:

root / trunk / code / projects / colonet / robot / joystick / simple_slave / slave.c @ 1349

History | View | Annotate | Download (2.52 KB)

1
#include <dragonfly_lib.h>
2
#include <wireless.h>
3
#include "../../../common/colonet_defs.h"
4

    
5
void packet_receive (char type, int source, unsigned char* packet, int length);
6

    
7
PacketGroupHandler packetHandler = {4, NULL, NULL, &packet_receive, NULL};
8

    
9
int main (void) {
10
  dragonfly_init(SERIAL | USB | COMM | ORB | ANALOG | MOTORS | BUZZER);
11
        ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
12
        //xbee_init();
13
    wl_init();
14
    wl_register_packet_group(&packetHandler);
15
        orb_set_color(PURPLE);
16
  
17
  /*char buf[100];
18
  char c;*/
19
  while (1) {
20
    //usb_puts("entering while loop\n");
21
    wl_do();
22
//    c = xbee_getc();
23
//    orb_set_color(GREEN);
24
//    sprintf(buf, "got char: %c\n", c);
25
//    usb_puts(buf);
26
    
27
    /*if (c == 'f') {
28
      orb_set_color(GREEN);
29
      motor1_set(1, 250);
30
      motor2_set(1, 250);
31
    }
32
    if (c == 'b') {
33
      orb_set_color(BLUE);
34
      motor1_set(0, 250);
35
      motor2_set(0, 250);
36
    }
37
    if (c == 'l') {
38
      orb_set_color(ORANGE);
39
      motor1_set(0, 250);
40
      motor2_set(1, 250);
41
    }
42
    if (c == 'r') {
43
      orb_set_color(YELLOW);
44
      motor1_set(1, 250);
45
      motor2_set(0, 250);
46
    }
47
    if (c == 's') {
48
      orb_set_color(RED);
49
      motor1_set(0, 0);
50
      motor2_set(0, 0);
51
    }
52
    if (c == 't') {
53
      orb_set_color(PURPLE);
54
      buzzer_chirp(1000, C5);
55
    }
56
    if (c == 'u') {
57
      orb_set_color(YELLOW);
58
      buzzer_chirp(1000, A4);
59
    }
60
    
61
    delay_ms(100);*/
62
  }
63
  
64
}
65

    
66
void packet_receive (char type, int source, unsigned char* packet, int length) {
67
    switch (type) {
68
        case 'f':
69
            orb_set_color(GREEN);
70
            motor1_set(1, 250);
71
            motor2_set(1, 250);
72
            break;
73
        case 's':
74
            orb_set_color(RED);
75
            motor1_set(0, 0);
76
            motor2_set(0, 0);
77
            break;
78
        case 'b':
79
            orb_set_color(BLUE);
80
            motor1_set(0, 250);
81
            motor2_set(0, 250);
82
            break;
83
        case 'l':
84
            orb_set_color(ORANGE);
85
            motor1_set(0, 250);
86
            motor2_set(1, 250);
87
            break;
88
        case 'r':
89
            orb_set_color(YELLOW);
90
            motor1_set(1, 250);
91
            motor2_set(0, 250);
92
            break;
93
        case 't':
94
            orb_set_color(PURPLE);
95
            buzzer_chirp(1000, C5);
96
            break;
97
        case 'u':
98
            orb_set_color(YELLOW);
99
            buzzer_chirp(1000, A4);
100
            break;
101
        default:
102
            orb_set_color(RED);
103
            motor1_set(0, 0);
104
            motor2_set(0, 0);
105
            break;
106
    }
107
}
108