an example of transmitting floating numbers (RX)
Dependencies: C12832_lcd mbed zbee_lib
Fork of simple_zb_rx by
main.cpp@1:f8efb266270f, 2017-04-05 (annotated)
- Committer:
- ruslylove
- Date:
- Wed Apr 05 10:42:07 2017 +0000
- Revision:
- 1:f8efb266270f
- Parent:
- 0:c19cf740caf3
an example of transmitting floating numbers (RX)
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ruslylove | 0:c19cf740caf3 | 1 | #include "mbed.h" |
ruslylove | 0:c19cf740caf3 | 2 | #include "zbee.h" |
ruslylove | 0:c19cf740caf3 | 3 | #include "C12832_lcd.h" |
ruslylove | 0:c19cf740caf3 | 4 | |
ruslylove | 0:c19cf740caf3 | 5 | DigitalOut myled(LED1); |
ruslylove | 0:c19cf740caf3 | 6 | zbee zbee1(p9,p10,ZBEE_BAUD); |
ruslylove | 0:c19cf740caf3 | 7 | C12832_LCD lcd; |
ruslylove | 0:c19cf740caf3 | 8 | |
ruslylove | 0:c19cf740caf3 | 9 | char text[50]; // buffer read |
ruslylove | 1:f8efb266270f | 10 | char delimiter[1]; // for synchonisation |
ruslylove | 1:f8efb266270f | 11 | |
ruslylove | 1:f8efb266270f | 12 | float pot1; // pot1 value |
ruslylove | 1:f8efb266270f | 13 | float pot2; // pot2 value |
ruslylove | 0:c19cf740caf3 | 14 | |
ruslylove | 0:c19cf740caf3 | 15 | int main() { |
ruslylove | 1:f8efb266270f | 16 | |
ruslylove | 0:c19cf740caf3 | 17 | while(1) { |
ruslylove | 1:f8efb266270f | 18 | |
ruslylove | 1:f8efb266270f | 19 | while(delimiter[0]!='#') { // synchronisation with '#' |
ruslylove | 1:f8efb266270f | 20 | zbee1.ReceiveData(delimiter,1); // read a character for '#' |
ruslylove | 1:f8efb266270f | 21 | } |
ruslylove | 1:f8efb266270f | 22 | |
ruslylove | 1:f8efb266270f | 23 | zbee1.ReceiveData(text,20); // "#pot1=x.xx pot2=x.xx" |
ruslylove | 1:f8efb266270f | 24 | |
ruslylove | 1:f8efb266270f | 25 | sscanf(text,"#pot1=%f pot2=%f",&pot1, &pot2); // parse pot1 and pot2 values from text received |
ruslylove | 1:f8efb266270f | 26 | |
ruslylove | 1:f8efb266270f | 27 | lcd.cls(); // clear lcd screen |
ruslylove | 1:f8efb266270f | 28 | lcd.locate(1,1); // lcd location x=1,y=1 |
ruslylove | 1:f8efb266270f | 29 | lcd.printf("RX -> pot1=%.2f pot2=%.2f\n",pot1, pot2); // update lcd values of pot1 and pot2 |
ruslylove | 1:f8efb266270f | 30 | lcd.printf("pot1 + pot2 = %.2f",pot1+pot2); // summation of two values |
ruslylove | 1:f8efb266270f | 31 | wait(0.1); // delay for 0.1s |
ruslylove | 0:c19cf740caf3 | 32 | } |
ruslylove | 0:c19cf740caf3 | 33 | } |