通过以下几个示例来具体展开学习,了解红外遥控器原理及特性,学习红外遥控器的应用(干货版):
示例十、红外遥控器
ino文件源码:
//Arduino C demo
#include "IRremote.h"
IRrecv irrecv(4);
decode_results results;
unsigned long key;
unsigned long ir_value;
void IR_key() {
static double ir_LastTime;
if (irrecv.decode(&results)) {
ir_LastTime = millis();
ir_value = results.value;
if (results.value != 0xFFFFFFFF) {
key = results.value;
}
irrecv.resume();
} else if ((millis() - ir_LastTime) >= 180) {
key = 0;
}
else
ir_value = 0;
}
void setup() {
irrecv.enableIRIn();
Serial.begin(9600);
}
void loop() {
IR_key();
if (key == 0xFF02FD) {
Serial.println(0xFF02FD);
}
if (key == 0xFF9867) {
Serial.println(0xFF9867);
}
if (key == 0xFFE01F) {
Serial.println(0xFFE01F);
}
if (key == 0xFF906F) {
Serial.println(0xFF906F);
}
key = 0;
}
视频演示:
红外遥控器实验现象