an example of transmitting floating numbers (RX)

Dependencies:   C12832_lcd mbed zbee_lib

Fork of simple_zb_rx by Ruslee Sutthaweekul

Files at this revision

API Documentation at this revision

Comitter:
ruslylove
Date:
Wed Apr 05 10:42:07 2017 +0000
Parent:
0:c19cf740caf3
Commit message:
an example of transmitting floating numbers (RX)

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r c19cf740caf3 -r f8efb266270f main.cpp
--- a/main.cpp	Sat Mar 12 17:49:28 2016 +0000
+++ b/main.cpp	Wed Apr 05 10:42:07 2017 +0000
@@ -7,11 +7,27 @@
 C12832_LCD lcd;
 
 char text[50];  // buffer read
+char delimiter[1];  // for synchonisation
+
+float pot1; // pot1 value
+float pot2; // pot2 value
 
 int main() {
-    int i=1;    
+
     while(1) {
-        zbee1.ReceiveData(text,11);
-        lcd.printf("%i RX <- %s\n",i++,text);
+        
+        while(delimiter[0]!='#') {      // synchronisation with '#'
+            zbee1.ReceiveData(delimiter,1);   // read a character for '#'
+        }
+        
+        zbee1.ReceiveData(text,20);                 // "#pot1=x.xx pot2=x.xx"
+        
+        sscanf(text,"#pot1=%f pot2=%f",&pot1, &pot2);   // parse pot1 and pot2 values from text received
+        
+        lcd.cls();  // clear lcd screen
+        lcd.locate(1,1);    // lcd location x=1,y=1
+        lcd.printf("RX -> pot1=%.2f pot2=%.2f\n",pot1, pot2); // update lcd values of pot1 and pot2
+        lcd.printf("pot1 + pot2 = %.2f",pot1+pot2); // summation of two values
+        wait(0.1);                    // delay for 0.1s
     }
 }