Measured results of an XBee wireless sensor device are displayed a LCD on Nucleo board with an XBee coordinator which is in API mode.
Dependencies: TextLCD mbed xbee sample04_sens
Please refer to the following site for the details:
- http://developer.mbed.org/users/bokunimowakaru/code/xbee/wiki/Homepage (English)
- http://www.geocities.jp/bokunimowakaru/diy/xbee/xbee-nucleo.html (Japanese)
Diff: main.cpp
- Revision:
- 9:f107d2c9cd6e
- Parent:
- 8:a114c798d954
--- a/main.cpp Sat Oct 04 01:43:12 2014 +0000 +++ b/main.cpp Sat Oct 04 03:12:27 2014 +0000 @@ -37,18 +37,15 @@ TextLCD lcd(PA_9, PC_7, PB_5, PB_4, PB_10, PA_8); // rs, e, d4-d7 byte dev_sens[8]; // IEEE Address -void setup(){ - lcd.cls(); lcd.printf("Sample 4 SENS"); - xbee_init( 0x00 ); // XBee用COMポートの初期化(引数はポート番号) -} - -void loop(){ +int main(){ int i; - int dev_en = 0; // センサー発見の有無(0:未発見) + int dev_en = 0; // センサー発見の有無(0:未発見) XBEE_RESULT xbee_result; // 受信データ用の構造体 int trig=0; float value; + lcd.cls(); lcd.printf("Sample 4 SENS"); + xbee_init( 0x00 ); // XBee用COMポートの初期化(引数はポート番号) // デバイス探索 lcd.cls(); lcd.printf("Searching:SENSOR"); if( xbee_atnj(10) ){ // 10秒間の参加受け入れ @@ -64,11 +61,11 @@ lcd.cls(); // メイン処理 - while(1){ // 永久に受信する + while(1){ // 永久に受信する if(dev_en){ if(trig<=0){ lcd.locate(12,0); lcd.printf("Trig"); wait(0.1); - xbee_force(dev_sens); // デバイスdev_sensへデータ要求 + xbee_force(dev_sens); // デバイスdev_sensへデータ要求 trig = FORCE_INTERVAL; lcd.locate(12,0); lcd.printf(" "); } @@ -80,10 +77,10 @@ trig--; /* データ受信(待ち受けて受信する) */ - xbee_rx_call( &xbee_result ); // データを受信します。 - switch( xbee_result.MODE ){ // 受信したデータの内容(MODE値)に応じて - case MODE_RESP: // sensorからの応答の場合に照度と温度を表示 - case MODE_GPIN: // 周期方式でデータ受信した場合も想定 + xbee_rx_call( &xbee_result ); // データを受信します。 + switch( xbee_result.MODE ){ // 受信したデータの内容(MODE値)に応じて + case MODE_RESP: // sensorからの応答の場合に照度と温度を表示 + case MODE_GPIN: // 周期方式でデータ受信した場合も想定 if( bytecmp( dev_sens , &(xbee_result.FROM[0]) ,8 ) == 0 && xbee_result.STATUS == STATUS_OK ){ // 照度測定結果 value = xbee_sensor_result( &xbee_result, LIGHT); @@ -108,8 +105,3 @@ } } } - -int main(){ - setup(); - while(1) loop(); -} \ No newline at end of file