Receive data from maxbotix rangefinder with xbee. Illuminate BUS leds if something is within 2 feet.
Dependencies: C12832_lcd mbed xbee_lib
main.cpp@0:0ae2b2f49936, 2015-02-16 (annotated)
- Committer:
- dannellyz
- Date:
- Mon Feb 16 02:28:48 2015 +0000
- Revision:
- 0:0ae2b2f49936
round 1;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
dannellyz | 0:0ae2b2f49936 | 1 | #include "mbed.h" |
dannellyz | 0:0ae2b2f49936 | 2 | #include "xbee.h" |
dannellyz | 0:0ae2b2f49936 | 3 | #include "C12832_lcd.h" // Include for LCD code |
dannellyz | 0:0ae2b2f49936 | 4 | #include <stdio.h> |
dannellyz | 0:0ae2b2f49936 | 5 | xbee xbee1(p9,p10,p30); //Initalise xbee_lib |
dannellyz | 0:0ae2b2f49936 | 6 | Serial pc(USBTX, USBRX); //Initalise PC serial comms |
dannellyz | 0:0ae2b2f49936 | 7 | C12832_LCD lcd; |
dannellyz | 0:0ae2b2f49936 | 8 | BusOut leds(LED1,LED2,LED3,LED4); |
dannellyz | 0:0ae2b2f49936 | 9 | int main() { |
dannellyz | 0:0ae2b2f49936 | 10 | char read_data[2]; //Xbee buffer size is 202 bytes |
dannellyz | 0:0ae2b2f49936 | 11 | int out = 0; |
dannellyz | 0:0ae2b2f49936 | 12 | while(1) { |
dannellyz | 0:0ae2b2f49936 | 13 | xbee1.RecieveData(read_data,2); //Read data from the XBee |
dannellyz | 0:0ae2b2f49936 | 14 | out = atoi(read_data); |
dannellyz | 0:0ae2b2f49936 | 15 | //If something is closer than 2ft illumiate BUS leds |
dannellyz | 0:0ae2b2f49936 | 16 | if(out < 24){ |
dannellyz | 0:0ae2b2f49936 | 17 | leds = 0xFFFF; |
dannellyz | 0:0ae2b2f49936 | 18 | } |
dannellyz | 0:0ae2b2f49936 | 19 | else{leds = 0;} |
dannellyz | 0:0ae2b2f49936 | 20 | pc.printf("Range: %s \r",read_data); |
dannellyz | 0:0ae2b2f49936 | 21 | lcd.cls(); |
dannellyz | 0:0ae2b2f49936 | 22 | lcd.locate(0,2); |
dannellyz | 0:0ae2b2f49936 | 23 | lcd.printf("Range: %s \r",read_data); |
dannellyz | 0:0ae2b2f49936 | 24 | wait(.1); |
dannellyz | 0:0ae2b2f49936 | 25 | } |
dannellyz | 0:0ae2b2f49936 | 26 | } |