Arduino 之 红外遥控

 1 /*
 2  * IRrecvDemo
 3  * 红外控制,接收红外命令控制板载LED灯亮灭
 4  */
 5 
 6 #include <IRremote.h>
 7 
 8 int RECV_PIN = 2;
 9 int LED_PIN = 13;
10 
11 IRrecv irrecv(RECV_PIN);
12 
13 decode_results results;
14 
15 void setup()
16 {
17   Serial.begin(115200);
18   irrecv.enableIRIn(); // Start the receiver
19   pinMode(LED_PIN, OUTPUT);
20   digitalWrite(LED_PIN, HIGH);
21 }
22 
23 void loop() {
24   if (irrecv.decode(&results)) {
25     Serial.println(results.value, HEX);
26     if (results.value == 0x44BB3BC4) //开灯的值
27     {
28       fadeToBlackBy( leds, NUM_LEDS, 10);
29     } else if (results.value == 0x44BB8F70) //关灯的值
30     {
31       digitalWrite(LED_PIN, HIGH);
32     }
33     irrecv.resume(); // Receive the next value
34   }
35   delay(100);
36 }
posted @ 2019-12-13 14:33  loadbxh  阅读(233)  评论(0)    收藏  举报