通过以下几个示例来具体展开学习,了解红外接收模块原理及特性,学习红外接收模块的应用(干货版):
示例九、红外接收模块
ino文件源码:
//Arduino C demoIRrecv 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;}elseir_value = 0;
}void setup() {irrecv.enableIRIn();pinMode(5, OUTPUT);
}void loop() {IR_key();if (key == 0xFFA857) {digitalWrite(5, 1);}key = 0;
}
演示视频:
红外接收头实验现象