To push buttons (or switches) on an XBee ZB device report the conditions of input ports on it to a Nucleo board, and display them on a LCD.

Dependencies:   TextLCD mbed xbee

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*********************************************************************
00002 サンプルアプリ2 スイッチ
00003 子機のスイッチ2~4(Port1~3)を押した時に、その状態を液晶に表示します。
00004 XBee子機のDIO1~3(XBee_pin 19~17)をHigh や Low にすると PCまたはH8の
00005 親機にスイッチの状態が表示されます。
00006 
00007 Sample Code 2 Switch
00008 To push buttons on an XBee ZB device report the conditions of input
00009 ports on it to a Nucleo board, and display them on a LCD.
00010 When you will use this anything other than Nucleo microcomputer board,
00011 please change the 4th line of xbee/xbee.cpp:
00012 RawSerial _xbee_serial(SERIAL_TX, SERIAL_RX);
00013         
00014 本ソースリストおよびソフトウェアは、ライセンスフリーです。
00015 利用、編集、再配布等が自由に行えますが、著作権表示の改変は禁止します。
00016 
00017                                Copyright (c) 2010-2014 Wataru KUNINO
00018                                http://www.geocities.jp/bokunimowakaru/
00019 *********************************************************************/
00020 /*
00021     port:   port指定  IO名 ピン番号           USB評価ボード(XBIB-U-Dev)
00022             port=11     DIO11   XBee_pin  7     LED2    ※port11がLED2
00023             port=12     DIO12   XBee_pin  4     LED1    ※port12がLED1
00024 */
00025 #include "xbee.h"
00026 #include "TextLCD.h"
00027 TextLCD lcd(PA_9, PC_7, PB_5, PB_4, PB_10, PA_8); // rs, e, d4-d7
00028 
00029 
00030 int main(){
00031     byte data;
00032     int i;
00033     XBEE_RESULT xbee_result;
00034     // お手持ちのXBee子機(リモート先)アドレスに変更して下さい ↓
00035     byte dev_gpio[]   = {0x00,0x13,0xA2,0x00,0x40,0x30,0xC1,0x6F};
00036     
00037     // 初期化処理
00038     lcd.cls(); lcd.printf("Sample 2 SW");
00039     xbee_init( 0x00 );                  // XBee用COMポートの初期化(引数はポート番号)
00040     lcd.cls(); lcd.printf("ATNJ");
00041     xbee_atnj( 0xFF );                  // デバイスを常に参加受け入れ(テスト用)
00042     lcd.cls(); lcd.printf("gpio init");
00043     xbee_gpio_init(dev_gpio);           // デバイスdev_gpioにIO設定を行うための送信
00044     lcd.cls(); lcd.printf("DONE");
00045     
00046     // メイン処理
00047     while(1){                           // 永久に受信する
00048         /* データ受信(待ち受けて受信する) */
00049         data = xbee_rx_call( &xbee_result );
00050                                         // データを受信します。
00051                                         // data:受信結果が代入されます
00052         if( xbee_result.MODE == MODE_GPIN){     // PIO入力(リモート機のボタンが押された)の時
00053             lcd.cls();
00054             for( i=7; i>=0 ; i--) lcd.printf( "%c",(char)( (int)'0' + ((data>>i) & 0x01) ) );
00055                                         // dataに入った値をバイナリで表示
00056         }
00057     }
00058 }