code for each end node in mesh network

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
dannellyz
Date:
Fri Jun 12 14:57:26 2015 +0000
Commit message:
code to go on each end node;

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 53f764257723 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Jun 12 14:57:26 2015 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+#include <stdio.h>
+#include <string.h>
+
+BusIn joy(p15,p12,p13,p16); //Initialize joystick bus
+//Initialize Potentiaometers
+AnalogIn pot1(p19);
+AnalogIn pot2(p20);
+Serial pc(USBTX, USBRX); //Initalise PC serial comms
+Serial xbeeOut(p9, p10);    //tx, rx via Xbee socket
+
+
+int main()
+{
+
+    float waitTime;     //Hold random time delay
+    float min = 0.05;    //Define minimum time
+    float max = 0.2;   //Define maximumtime
+
+    while(1) {
+        //Serial number identifies which mbed it is transmitting
+        int serial_no = 1;
+        //This can be customized to take any other internal or external sensors
+        int joystick = joy;
+        float Lpot = pot1;
+        float Rpot = pot2;
+        //Echo locally for error checking
+        printf("$APPBOARD,%.02f,%.02f,%d,%d %f\r\n",Lpot,Rpot,joystick,serial_no,waitTime);
+        //Use the same serial fictions as above the transmit over XBee
+        xbeeOut.printf("$APPBOARD,%.02f,%.02f,%d,%d\r\n",Lpot,Rpot,joystick,serial_no);
+        //Wait the calculated randomized time
+        if(pot1 > .5) {
+            waitTime = min + ((float)rand()/RAND_MAX) * (max - min);
+            wait(waitTime);
+        }
+
+    }
+}
diff -r 000000000000 -r 53f764257723 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Jun 12 14:57:26 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/433970e64889
\ No newline at end of file