/ *******************************************************************/
//  FILE        赤外線リモコン受信ユニット OSRB38C9AA 
//  DATE        :Tue, Jan 10, 2025                                  
//  DESCRIPTION : 赤外線リモコン受信ユニット OSRB38C9AA/
//
//  CPU TYPE    : Arduino UNO 
//                                    					by Chiyabo
//  This file is generated by Renesas Project Generator.
//
/*******************************************************************/
#include < LiquidCrystal_I2C.h >  // ライブラリのインクルード
#include < IRremote.hpp >
                                                                  
#define IR_RECEIVE_PIN  7  //受信ピン指定
//PCモニターを使用しない場合は //#define	Silial_EN	とすること。
#define	Silial_EN	

LiquidCrystal_I2C lcd( 0x27, 16 , 2 ) ;// 0x27のアドレス,16列2行のLCDを使用
IRrecv rcvdata(IR_RECEIVE_PIN); // 受信オブジェクトを作成 

void setup( ){
  #ifdef  Silial_EN	
    Serial.begin(9600);  //シリアル通信のビットレート
  #endif
  lcd.init( ) ;                       	// LCDの初期化
  lcd.backlight( ) ;             	// LCDバックライトの点灯
  lcd.setCursor( 0, 0 ) ;     	// カーソルの位置を指定
  lcd.print( "Addres  " ) ;  	// カスタムコード(HEX)
  lcd.print( "Command" ) ; 	// データコード(HEX)  
  IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
}
 
void loop( ){
  char Address ;
  char Command ;
  // put your main code here, to run repeatedly:
  if (IrReceiver.decode( ) ){ // 受信確認
    #ifdef  Silial_EN
      Serial.println( IrReceiver.decodedIRData.decodedRawData, HEX ) ; // Print "old" raw data
      IrReceiver.printIRResultShort( &Serial ) ; // Print complete received data in one line
      IrReceiver.printIRSendUsage( &Serial ) ;   // Print the statement required to send this data
    #endif
    // LCDにアドレス&コマンドを表示                          
    Address = ( char )( IrReceiver.decodedIRData.decodedRawData & 0x000000ff ) ; 
    Command = ( char )( ( IrReceiver.decodedIRData.decodedRawData & 0x00ff0000 ) >> 16 ) ; 
    Serial.println( Address, HEX ) ;
    Serial.println( Command, HEX ) ;
    
    lcd.setCursor( 0, 1 ) ; 
    lcd.print( Address, HEX ) ; //アドレス確認 
    lcd.print( "[HEX]  " ) ; 
    lcd.print( Command, HEX );  //コマンド確認
    lcd.print( "[HEX] " ) ; 
    
    IrReceiver.resume( ) ; // Enable receiving of the next value
  } 
  delay( 100 ) ;              
}