Statistics
| Revision:

root / demos / joystick / src / joystick / simple_slave / slave.c @ 1742

History | View | Annotate | Download (1.9 KB)

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

    
5
/* Command Types */
6
#define CNTL_FORWARD 'f'
7
#define CNTL_STOP    's'
8
#define CNTL_BACK    'b'
9
#define CNTL_LEFT    'l'
10
#define CNTL_RIGHT   'r'
11
#define CNTL_BUZZ0   't'
12
#define CNTL_BUZZ1   'u'
13

    
14
#define WL_CNTL_GROUP 4
15

    
16
void packet_receive (char type, int source, unsigned char* packet, int length);
17

    
18
PacketGroupHandler packetHandler = {WL_CNTL_GROUP, NULL, NULL, &packet_receive, NULL};
19

    
20
int main (void) {
21
        dragonfly_init(SERIAL | USB | COMM | ORB | ANALOG | MOTORS | BUZZER);
22
        ADCSRA = _BV(ADEN) | _BV(ADPS2) | _BV(ADPS1) | _BV(ADPS0);
23
    wl_init();
24
    wl_register_packet_group(&packetHandler);
25
        orb_set_color(PURPLE);
26
  
27
          while (1) {
28
            wl_do();
29
            delay_ms(100);
30
          }
31
}
32

    
33
void packet_receive (char type, int source, unsigned char* packet, int length) {
34
    switch (type) {
35
        case CNTL_FORWARD:
36
            orb_set_color(GREEN);
37
            motor1_set(1, 250);
38
            motor2_set(1, 250);
39
            break;
40
        case CNTL_STOP:
41
            orb_set_color(RED);
42
            motor1_set(0, 0);
43
            motor2_set(0, 0);
44
            break;
45
        case CNTL_BACK:
46
            orb_set_color(BLUE);
47
            motor1_set(0, 250);
48
            motor2_set(0, 250);
49
            break;
50
        case CNTL_LEFT:
51
            orb_set_color(ORANGE);
52
            motor1_set(0, 250);
53
            motor2_set(1, 250);
54
            break;
55
        case CNTL_RIGHT:
56
            orb_set_color(YELLOW);
57
            motor1_set(1, 250);
58
            motor2_set(0, 250);
59
            break;
60
        case CNTL_BUZZ0:
61
            orb_set_color(PURPLE);
62
            buzzer_chirp(1000, C5);
63
            break;
64
        case CNTL_BUZZ1:
65
            orb_set_color(YELLOW);
66
            buzzer_chirp(1000, A4);
67
            break;
68
        default:
69
            orb_set_color(RED);
70
            motor1_set(0, 0);
71
            motor2_set(0, 0);
72
            break;
73
    }
74
}
75