xbee shield simple test code

Dependencies:   mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 
00003 /*------------------------------------------------------------------------------
00004 Before to use this example, ensure that you an hyperterminal installed on your
00005 computer. More info here: https://developer.mbed.org/handbook/Terminals
00006 
00007 The default serial comm port uses the SERIAL_TX and SERIAL_RX pins (see their
00008 definition in the PinNames.h file).
00009 
00010 The default serial configuration in this case is 9600 bauds, 8-bit data, no parity
00011 
00012 If you want to change the baudrate for example, you have to redeclare the
00013 serial object in your code:
00014 
00015 Serial pc(SERIAL_TX, SERIAL_RX);
00016 
00017 Then, you can modify the baudrate and print like this:
00018 
00019 pc.baud(115200);
00020 pc.printf("Hello World !\n");
00021 ------------------------------------------------------------------------------*/
00022 
00023 DigitalOut led(LED1);
00024 
00025 Serial pc(SERIAL_TX, SERIAL_RX);
00026 Serial xbee(PA_9, PA_10);
00027 
00028 int main()
00029 {
00030     pc.baud(9600);
00031 xbee.baud(9600);
00032     int i = 1;
00033 
00034     pc.printf("Hello World pc!\r\n");
00035     xbee.printf("Hello World Xbee!\r\n");
00036 
00037     while(1) {
00038         wait(1); // 1 second
00039         led = !led; // Toggle LED
00040         pc.printf("PC - This program runs since %d seconds.\r\n", i++);
00041         xbee.printf("Xbee - This program runs since %d seconds.\r\n", i++);
00042     }
00043 }