Analog comms with xbee. Program for the End Device.

Dependencies:   C12832_lcd Xbee_Hello_world_A mbed xbeeLibDannelly

Fork of Xbee_Hello_world_A by Tristan Hughes

Committer:
dannellyz
Date:
Sun Feb 15 16:42:43 2015 +0000
Revision:
1:8a191a1f56fb
Parent:
0:9cbddcc86466
round 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tristanjph 0:9cbddcc86466 1 #include "mbed.h"
dannellyz 1:8a191a1f56fb 2 #include "xbee.h" // Include for xbee code
dannellyz 1:8a191a1f56fb 3 #include "C12832_lcd.h" // Include for LCD code
dannellyz 1:8a191a1f56fb 4 #include <stdio.h> //Include for sprintf
tristanjph 0:9cbddcc86466 5
dannellyz 1:8a191a1f56fb 6 xbee xbee1(p9,p10,p30); //Initalise xbee_lib varName(rx,tx,reset)
dannellyz 1:8a191a1f56fb 7 DigitalOut rst1(p30);
tristanjph 0:9cbddcc86466 8 Serial pc(USBTX, USBRX); //Initalise PC serial comms
dannellyz 1:8a191a1f56fb 9 C12832_LCD lcd; //Initialize LCD Screen
tristanjph 0:9cbddcc86466 10
dannellyz 1:8a191a1f56fb 11
dannellyz 1:8a191a1f56fb 12 //Initialize Potentiaometers
dannellyz 1:8a191a1f56fb 13 AnalogIn pot1(p19);
dannellyz 1:8a191a1f56fb 14 AnalogIn pot2(p20);
tristanjph 0:9cbddcc86466 15 int main()
tristanjph 0:9cbddcc86466 16 {
dannellyz 1:8a191a1f56fb 17 char send_data1[202]; //Xbee buffer size is 202 bytes
dannellyz 1:8a191a1f56fb 18
dannellyz 1:8a191a1f56fb 19 // reset the xbees (at least 200ns)
dannellyz 1:8a191a1f56fb 20 rst1 = 0;
dannellyz 1:8a191a1f56fb 21 wait_ms(1);
dannellyz 1:8a191a1f56fb 22 rst1 = 1;
dannellyz 1:8a191a1f56fb 23 wait_ms(1);
tristanjph 0:9cbddcc86466 24
dannellyz 1:8a191a1f56fb 25 //Give time for other Xbee to come online
dannellyz 1:8a191a1f56fb 26 wait(1);
dannellyz 1:8a191a1f56fb 27
tristanjph 0:9cbddcc86466 28 while(1) {
dannellyz 1:8a191a1f56fb 29 //Set up LCD and print
dannellyz 1:8a191a1f56fb 30 lcd.cls();
dannellyz 1:8a191a1f56fb 31 lcd.locate(0,2);
dannellyz 1:8a191a1f56fb 32 lcd.printf("Pot 1 = %.2f", (float)pot1);
dannellyz 1:8a191a1f56fb 33 lcd.locate(0,14);
dannellyz 1:8a191a1f56fb 34 lcd.printf("Pot 2 = %.2f", (float)pot2);
dannellyz 1:8a191a1f56fb 35
dannellyz 1:8a191a1f56fb 36 wait(0.1);
dannellyz 1:8a191a1f56fb 37
dannellyz 1:8a191a1f56fb 38 //In AT mode we are constantly transmitting so it is
dannellyz 1:8a191a1f56fb 39 //necessary to implement an external protocol
dannellyz 1:8a191a1f56fb 40 //see https://developer.mbed.org/users/dannellyz/notebook/at-vs-api-when-why-how/#
dannellyz 1:8a191a1f56fb 41
dannellyz 1:8a191a1f56fb 42 //Format is aPOT1bPOT2 to send
dannellyz 1:8a191a1f56fb 43 sprintf (send_data1, "a%.2fb%.2f", (float)pot1,(float)pot2);
dannellyz 1:8a191a1f56fb 44 xbee1.SendData(send_data1); //Send data to XBee
dannellyz 1:8a191a1f56fb 45
dannellyz 1:8a191a1f56fb 46
tristanjph 0:9cbddcc86466 47 }
tristanjph 0:9cbddcc86466 48 }