SONG BONG SOO
/
Xbee_Hello_world_Add
example
Fork of Xbee_Hello_world_A by
main.cpp@2:c28639345230, 2017-11-11 (annotated)
- Committer:
- mdo131
- Date:
- Sat Nov 11 18:55:21 2017 +0000
- Revision:
- 2:c28639345230
- Parent:
- 1:114432971517
..
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
tristanjph | 0:9cbddcc86466 | 1 | #include "mbed.h" |
tristanjph | 0:9cbddcc86466 | 2 | #include "xbee.h" |
tristanjph | 0:9cbddcc86466 | 3 | |
mdo131 | 2:c28639345230 | 4 | //xbee xbee1(D1,D0,D3); //Initalise xbee_lib |
tristanjph | 0:9cbddcc86466 | 5 | Serial pc(USBTX, USBRX); //Initalise PC serial comms |
mdo131 | 2:c28639345230 | 6 | Serial xbee(D1,D0); |
mdo131 | 2:c28639345230 | 7 | |
mdo131 | 2:c28639345230 | 8 | unsigned char input; |
mdo131 | 2:c28639345230 | 9 | char buff[100]; |
tristanjph | 0:9cbddcc86466 | 10 | |
tristanjph | 0:9cbddcc86466 | 11 | int main() |
tristanjph | 0:9cbddcc86466 | 12 | { |
mdo131 | 2:c28639345230 | 13 | |
mdo131 | 2:c28639345230 | 14 | pc.printf("hahaha\r\n"); |
mdo131 | 2:c28639345230 | 15 | |
tristanjph | 0:9cbddcc86466 | 16 | while(1) { |
mdo131 | 2:c28639345230 | 17 | |
mdo131 | 2:c28639345230 | 18 | if(pc.readable()) |
mdo131 | 2:c28639345230 | 19 | { |
mdo131 | 2:c28639345230 | 20 | pc.printf("ho\r\n"); |
mdo131 | 2:c28639345230 | 21 | input = pc.getc(); |
mdo131 | 2:c28639345230 | 22 | |
mdo131 | 2:c28639345230 | 23 | if(input=='a') |
mdo131 | 2:c28639345230 | 24 | { |
mdo131 | 2:c28639345230 | 25 | xbee.putc('a'); |
mdo131 | 2:c28639345230 | 26 | xbee.getc(); |
mdo131 | 2:c28639345230 | 27 | wait(0.1); |
mdo131 | 2:c28639345230 | 28 | xbee.printf("+++"); |
mdo131 | 2:c28639345230 | 29 | |
mdo131 | 2:c28639345230 | 30 | xbee.getc(); |
mdo131 | 2:c28639345230 | 31 | xbee.getc(); |
mdo131 | 2:c28639345230 | 32 | xbee.getc(); |
mdo131 | 2:c28639345230 | 33 | |
mdo131 | 2:c28639345230 | 34 | xbee.printf("ATDB\r"); |
mdo131 | 2:c28639345230 | 35 | xbee.scanf("%s",buff); |
mdo131 | 2:c28639345230 | 36 | pc.printf("%s",buff); |
mdo131 | 2:c28639345230 | 37 | } |
mdo131 | 2:c28639345230 | 38 | else if(input=='s') |
mdo131 | 2:c28639345230 | 39 | { |
mdo131 | 2:c28639345230 | 40 | xbee.putc('b'); |
mdo131 | 2:c28639345230 | 41 | xbee.getc(); |
mdo131 | 2:c28639345230 | 42 | wait(0.1); |
mdo131 | 2:c28639345230 | 43 | xbee.printf("+++"); |
mdo131 | 2:c28639345230 | 44 | |
mdo131 | 2:c28639345230 | 45 | xbee.getc(); |
mdo131 | 2:c28639345230 | 46 | xbee.getc(); |
mdo131 | 2:c28639345230 | 47 | xbee.getc(); |
mdo131 | 2:c28639345230 | 48 | |
mdo131 | 2:c28639345230 | 49 | xbee.printf("ATDB\r"); |
mdo131 | 2:c28639345230 | 50 | xbee.scanf("%s",buff); |
mdo131 | 2:c28639345230 | 51 | pc.printf("%s",buff); |
mdo131 | 2:c28639345230 | 52 | } |
mdo131 | 2:c28639345230 | 53 | else if(input=='d') |
mdo131 | 2:c28639345230 | 54 | { |
mdo131 | 2:c28639345230 | 55 | xbee.putc('c'); |
mdo131 | 2:c28639345230 | 56 | xbee.getc(); |
mdo131 | 2:c28639345230 | 57 | wait(0.1); |
mdo131 | 2:c28639345230 | 58 | xbee.printf("+++"); |
mdo131 | 2:c28639345230 | 59 | |
mdo131 | 2:c28639345230 | 60 | xbee.getc(); |
mdo131 | 2:c28639345230 | 61 | xbee.getc(); |
mdo131 | 2:c28639345230 | 62 | xbee.getc(); |
mdo131 | 2:c28639345230 | 63 | |
mdo131 | 2:c28639345230 | 64 | xbee.printf("ATDB\r"); |
mdo131 | 2:c28639345230 | 65 | xbee.scanf("%s",buff); |
mdo131 | 2:c28639345230 | 66 | pc.printf("%s",buff); |
mdo131 | 2:c28639345230 | 67 | } |
mdo131 | 2:c28639345230 | 68 | else if(input=='f') |
mdo131 | 2:c28639345230 | 69 | { |
mdo131 | 2:c28639345230 | 70 | xbee.putc('d'); |
mdo131 | 2:c28639345230 | 71 | xbee.getc(); |
mdo131 | 2:c28639345230 | 72 | wait(0.1); |
mdo131 | 2:c28639345230 | 73 | xbee.printf("+++"); |
mdo131 | 2:c28639345230 | 74 | |
mdo131 | 2:c28639345230 | 75 | xbee.getc(); |
mdo131 | 2:c28639345230 | 76 | xbee.getc(); |
mdo131 | 2:c28639345230 | 77 | xbee.getc(); |
mdo131 | 2:c28639345230 | 78 | |
mdo131 | 2:c28639345230 | 79 | xbee.printf("ATDB\r"); |
mdo131 | 2:c28639345230 | 80 | xbee.scanf("%s",buff); |
mdo131 | 2:c28639345230 | 81 | pc.printf("%s",buff); |
mdo131 | 2:c28639345230 | 82 | } |
mdo131 | 2:c28639345230 | 83 | } |
tristanjph | 0:9cbddcc86466 | 84 | } |
tristanjph | 0:9cbddcc86466 | 85 | } |
mdo131 | 1:114432971517 | 86 | |
mdo131 | 1:114432971517 | 87 | //about xbee pro |
mdo131 | 1:114432971517 | 88 | //https://os.mbed.com/components/Xbee-Pro/ |