Ashwin Rana / Mbed 2 deprecated xbeeLEDControl

Dependencies:   mbed

Committer:
co657_at435
Date:
Wed Dec 16 18:14:46 2015 +0000
Revision:
0:657f19640bf8
initial xbeeLEDController;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
co657_at435 0:657f19640bf8 1 // Chinese knock off Philips hue
co657_at435 0:657f19640bf8 2
co657_at435 0:657f19640bf8 3 #include "mbed.h"
co657_at435 0:657f19640bf8 4
co657_at435 0:657f19640bf8 5 /* LEDs */
co657_at435 0:657f19640bf8 6 DigitalOut red_led(D5);
co657_at435 0:657f19640bf8 7 DigitalOut blue_led(PTC12);
co657_at435 0:657f19640bf8 8 DigitalOut green_led(D9);
co657_at435 0:657f19640bf8 9
co657_at435 0:657f19640bf8 10 Serial xbee(D1,D0);
co657_at435 0:657f19640bf8 11 Serial mac( USBTX , USBRX );
co657_at435 0:657f19640bf8 12
co657_at435 0:657f19640bf8 13 bool isLeader = false;
co657_at435 0:657f19640bf8 14 char group;
co657_at435 0:657f19640bf8 15
co657_at435 0:657f19640bf8 16 void ChangeColour(char rgb)
co657_at435 0:657f19640bf8 17 {
co657_at435 0:657f19640bf8 18 bool R = rgb & 0x4;
co657_at435 0:657f19640bf8 19 bool G = rgb & 0x2;
co657_at435 0:657f19640bf8 20 bool B = rgb & 0x1;
co657_at435 0:657f19640bf8 21
co657_at435 0:657f19640bf8 22 mac.printf("Red: %d, Green: %d, Blue %d\n",R,G,B);
co657_at435 0:657f19640bf8 23
co657_at435 0:657f19640bf8 24 red_led = !R;
co657_at435 0:657f19640bf8 25 green_led = !G;
co657_at435 0:657f19640bf8 26 blue_led = !B;
co657_at435 0:657f19640bf8 27 }
co657_at435 0:657f19640bf8 28
co657_at435 0:657f19640bf8 29 void ListenXbee(void)
co657_at435 0:657f19640bf8 30 {
co657_at435 0:657f19640bf8 31 //read Xbee if possible \
co657_at435 0:657f19640bf8 32 while (xbee.readable())
co657_at435 0:657f19640bf8 33 {
co657_at435 0:657f19640bf8 34 char message = xbee.getc();
co657_at435 0:657f19640bf8 35 mac.printf("%d\n",(int)message);
co657_at435 0:657f19640bf8 36 ChangeColour(message);
co657_at435 0:657f19640bf8 37 }
co657_at435 0:657f19640bf8 38 }
co657_at435 0:657f19640bf8 39
co657_at435 0:657f19640bf8 40 int main () {
co657_at435 0:657f19640bf8 41 mac.baud (38400);
co657_at435 0:657f19640bf8 42 mac.printf("We are reciving\n");
co657_at435 0:657f19640bf8 43 for (;;) {
co657_at435 0:657f19640bf8 44 if (!isLeader) {
co657_at435 0:657f19640bf8 45 ListenXbee();
co657_at435 0:657f19640bf8 46 }
co657_at435 0:657f19640bf8 47 wait_ms(100);
co657_at435 0:657f19640bf8 48 }
co657_at435 0:657f19640bf8 49 }
co657_at435 0:657f19640bf8 50
co657_at435 0:657f19640bf8 51
co657_at435 0:657f19640bf8 52
co657_at435 0:657f19640bf8 53