#author("2016-06-28T14:54:31+09:00","default:qua","qua")
* 赤外線リモコン受信モジュール GP1UXC41QS [#r1bf8850]
#ref(http://www.ist.aichi-pu.ac.jp/lab/qua/~qua/pbl/img/gp1uxc41qs.jpg,200x150)
-[[販売元情報ページ:http://akizukidenshi.com/catalog/g/gI-06487/]]
** 配線 [#od8d31a1]
受信部(半球の突起)を正面に向けて・・・
|ピン位置|名称|意味|h
|左|Vout|出力(Arduinoのデジタルピンへ)|
|中央|GND|Ground(ArduinoのGNDへ)|
|右|Vcc|電源(Arduinoの5Vへ)|
** プログラミング [#reded200]
リモコンの赤外線を検出したときにLOW, 検出しないときにHIGHが出力される。
以下にテレビの[[リモコンで使われる方式:http://elm-chan.org/docs/ir_format.html]]
の一つであるNECフォーマットのデータを表示するプログラム例を示す。
#author("2016-06-28T14:55:32+09:00","default:qua","qua")

 const int pin = 2;
 void setup() {
   pinMode( pin, INPUT );
   Serial.begin( 115200 );
 }
 unsigned long last, code;
 unsigned int custom;
 unsigned char data;
 void loop() {
   while ( 1 ) {
     while ( digitalRead( pin ) );
     last = micros();
     while ( !digitalRead( pin ) );
     if ( micros() - last > 8400 ) break;
   }
   last = micros();
   while ( digitalRead( pin ) );
   if ( micros() - last < 4200 ) {
     Serial.println( "Repeat" );
   } else {
     code = 0;
     for ( int i = 0; i < 32; i++ ) {
       while ( !digitalRead( pin ) );
       last = micros();
       code >>= 1;
       while ( digitalRead( pin ) );
       if ( micros() - last > 1400 ) code |= 0x80000000;
     }
     custom = code & 0xffff;
     data = (code >> 16) & 0xff;
     Serial.println( "custom=" + String( custom, HEX ) + " data=" + String( data, HEX ) );
   }
   while ( !digitalRead( pin ) );
 }


トップ   編集 差分 履歴 添付 複製 名前変更 リロード   新規 一覧 検索 最終更新   ヘルプ   最終更新のRSS