an example of transmitting floating numbers (TX)

Dependencies:   C12832_lcd mbed zbee_lib

Fork of simple_zb_tx by Ruslee Sutthaweekul

Committer:
ruslylove
Date:
Wed Apr 05 10:41:38 2017 +0000
Revision:
1:e344b49086eb
Parent:
0:57fe74d7e78b
an example of transmitting floating numbers (TX)

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ruslylove 0:57fe74d7e78b 1 #include "mbed.h"
ruslylove 0:57fe74d7e78b 2 #include "zbee.h"
ruslylove 0:57fe74d7e78b 3 #include "C12832_lcd.h"
ruslylove 0:57fe74d7e78b 4
ruslylove 0:57fe74d7e78b 5 DigitalOut myled(LED1);
ruslylove 1:e344b49086eb 6
ruslylove 1:e344b49086eb 7 AnalogIn pot1(p19); // Pot 1
ruslylove 1:e344b49086eb 8 AnalogIn pot2(p20); // Pot 2
ruslylove 1:e344b49086eb 9
ruslylove 0:57fe74d7e78b 10 zbee zbee1(p9,p10,ZBEE_BAUD);
ruslylove 0:57fe74d7e78b 11 C12832_LCD lcd;
ruslylove 0:57fe74d7e78b 12
ruslylove 1:e344b49086eb 13
ruslylove 1:e344b49086eb 14 char txt[40]; // text to send
ruslylove 1:e344b49086eb 15 char pot1_txt[20]; // text buffer for pot1 value
ruslylove 1:e344b49086eb 16 char pot2_txt[20]; // text buffer for pot2 value
ruslylove 0:57fe74d7e78b 17
ruslylove 0:57fe74d7e78b 18 int main() {
ruslylove 0:57fe74d7e78b 19
ruslylove 1:e344b49086eb 20
ruslylove 1:e344b49086eb 21 while(1) {
ruslylove 1:e344b49086eb 22
ruslylove 1:e344b49086eb 23 lcd.cls(); // clear lcd screen
ruslylove 1:e344b49086eb 24 lcd.locate(1,1); // text location x=1,y=1
ruslylove 1:e344b49086eb 25
ruslylove 1:e344b49086eb 26 sprintf(pot1_txt,"pot1=%.2f", pot1.read()); // read pot1 value and convert to text
ruslylove 1:e344b49086eb 27 sprintf(pot2_txt,"pot2=%.2f", pot2.read()); // read pot2 value and convert to text
ruslylove 1:e344b49086eb 28 sprintf(txt,"#%s %s",pot1_txt, pot2_txt); // put them together for sending
ruslylove 1:e344b49086eb 29
ruslylove 1:e344b49086eb 30 zbee1.SendData(txt); // send text
ruslylove 1:e344b49086eb 31
ruslylove 1:e344b49086eb 32 lcd.printf("TX -> %s %s\r",pot1_txt,pot2_txt); // update lcd display
ruslylove 1:e344b49086eb 33
ruslylove 1:e344b49086eb 34 wait(1); // delay for 1s
ruslylove 0:57fe74d7e78b 35 }
ruslylove 0:57fe74d7e78b 36 }