Arduino「IRremote.hpp」ライブラリを使用してラジコンを動かしたい
Q&A
解決したいこと
IRリモコンを使用し、LEDライトを点灯させたい
発生している問題・エラー
シリアルモニタで表示もなく、LEDも点滅しなかった
該当するソースコード
①を参考にしつつ、GithubのIRRemoteライブラリの新API(②)に書き換えてためした
①→https://deviceplus.jp/arduino/how-to-send-ir-commands-to-project-with-remote-control/#04
②→https://github.com/Arduino-IRremote/Arduino-IRremote#converting-your-2x-program-to-the-4x-version
sketch_may8a.ino
#include <IRremote.hpp>
#define IR_RECEIVE_PIN 8
#define LED_PIN 6
bool lightOn = false;
void setup() {
Serial.begin(9600);
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); // Start the receiver
pinMode(LED_PIN, OUTPUT);
}
void loop() {
if (IrReceiver.decode()) {
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
if (IrReceiver.decodedIRData.decodedRawData == 0x00000000) {
if (lightOn == true) {
digitalWrite(LED_PIN, LOW);
lightOn = false;
} else {
digitalWrite(LED_PIN, HIGH);
lightOn = true;
}
}
IrReceiver.resume(); // Enable receiving of the next value
}
}
自分で試したこと
赤外線センサーを下記図につけかえ、同じコードをうつと
LEDは光らなかったが、シリアルモニタで下記コードがでてきた
シリアルモニタコード
22:39:16.210 -> BA45FF00
22:39:16.210 -> Protocol=NEC Address=0x0 Command=0x45 Raw-Data=0xBA45FF00 32 bits LSB first
22:39:16.249 -> Send with: IrSender.sendNEC(0x0, 0x45, <numberOfRepeats>);
22:39:20.285 -> E916FF00
22:39:20.285 -> Protocol=NEC Address=0x0 Command=0x16 Raw-Data=0xE916FF00 32 bits LSB first
22:39:20.336 -> Send with: IrSender.sendNEC(0x0, 0x16, <numberOfRepeats>);
0 likes