Xbee Comm Test 2

Dependencies:   mbed xbee_lib

Committer:
ricefireflighter
Date:
Mon Feb 17 16:59:07 2014 +0000
Revision:
0:e8bf611e7036
Xbee2

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ricefireflighter 0:e8bf611e7036 1 #include "mbed.h"
ricefireflighter 0:e8bf611e7036 2 #include "xbee.h"
ricefireflighter 0:e8bf611e7036 3 #include "PwmOut.h"
ricefireflighter 0:e8bf611e7036 4
ricefireflighter 0:e8bf611e7036 5 int main()
ricefireflighter 0:e8bf611e7036 6 {
ricefireflighter 0:e8bf611e7036 7
ricefireflighter 0:e8bf611e7036 8 class xbee xbee1(PTD3,PTD2,PTD0); // Define xbee1 as an xbee class per xbee.h library
ricefireflighter 0:e8bf611e7036 9
ricefireflighter 0:e8bf611e7036 10 DigitalOut gled(LED_GREEN); // Initialize green led
ricefireflighter 0:e8bf611e7036 11 DigitalOut rled(LED_RED); // Initialize red led
ricefireflighter 0:e8bf611e7036 12 gled = 1;
ricefireflighter 0:e8bf611e7036 13 gled = 1;
ricefireflighter 0:e8bf611e7036 14
ricefireflighter 0:e8bf611e7036 15 //Configure xbee with PanID of 6969 and exit config mode. Vary LED status.
ricefireflighter 0:e8bf611e7036 16 //xbee1.ConfigMode();
ricefireflighter 0:e8bf611e7036 17 //wait(1);
ricefireflighter 0:e8bf611e7036 18 //xbee1.SetPanId(6969);
ricefireflighter 0:e8bf611e7036 19 //xbee1.ExitConfigMode();
ricefireflighter 0:e8bf611e7036 20
ricefireflighter 0:e8bf611e7036 21 //char send_data[202]; //Xbee buffer size is 202 bytes
ricefireflighter 0:e8bf611e7036 22 //send_data = 1;
ricefireflighter 0:e8bf611e7036 23 char read_data[202]; //Xbee buffer size is 202 bytes
ricefireflighter 0:e8bf611e7036 24
ricefireflighter 0:e8bf611e7036 25 while(1){
ricefireflighter 0:e8bf611e7036 26
ricefireflighter 0:e8bf611e7036 27 rled = 0;
ricefireflighter 0:e8bf611e7036 28 xbee1.RecieveData(read_data,0);
ricefireflighter 0:e8bf611e7036 29 // Line above receives data from xbee to FRDM as a char using getc.
ricefireflighter 0:e8bf611e7036 30 // See function definition for more info.
ricefireflighter 0:e8bf611e7036 31
ricefireflighter 0:e8bf611e7036 32 // Transfer information in read.data character string to useful motor/servo info here.
ricefireflighter 0:e8bf611e7036 33
ricefireflighter 0:e8bf611e7036 34 if (read_data == "B") {
ricefireflighter 0:e8bf611e7036 35
ricefireflighter 0:e8bf611e7036 36 gled = 0;
ricefireflighter 0:e8bf611e7036 37 wait(3);
ricefireflighter 0:e8bf611e7036 38
ricefireflighter 0:e8bf611e7036 39 }
ricefireflighter 0:e8bf611e7036 40
ricefireflighter 0:e8bf611e7036 41 wait(2);
ricefireflighter 0:e8bf611e7036 42 // Wait for some amount of time to allow for complete data to be sent/received
ricefireflighter 0:e8bf611e7036 43 }
ricefireflighter 0:e8bf611e7036 44 }