#include <Arduino.h>
#include <FastLED.h>
#include <IRremote.h>
#define IRsensorPin 11
IRrecv irrecv(IRsensorPin); //设定红外接收对象为irrecv
bool LEDkey = 0; //默认LED开关为关闭状态
void setup(){
Serial.begin(9600);
pinMode(IRsensorPin, INPUT);
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW); //默认LED灯位熄灭状态
irrecv.enableIRIn(); //启动红外接收功能
Serial.println("红外遥控功能已启用!");
}
void loop(){
if(irrecv.decode()){ //判断红外接收结果是否可以被解码
Serial.print("指令码为:");
Serial.println(irrecv.decodedIRData.command); //输出解码后的数据指令
switch(irrecv.decodedIRData.command){
case 162:
if(LEDkey == 0){ //判断LED开关状态
digitalWrite(LED_BUILTIN, HIGH);
Serial.println("开启内置LED");
LEDkey = 1; //LED开关为开启状态
}else if(LEDkey == 1){ //判断LED开关状态
digitalWrite(LED_BUILTIN, LOW);
Serial.println("关闭内置LED");
LEDkey = 0; //LED开关为关闭状态
}
break;
case 226:
Serial.println("打开菜单");
break;
case 34:
Serial.println("进入测试模式");
break;
case 194:
Serial.println("返回");
break;
case 2:
Serial.println("音量增加");
break;
case 152:
Serial.println("音量减少");
break;
case 224:
Serial.println("上一个");
break;
case 144:
Serial.println("下一个");
break;
case 168:
Serial.println("播放");
break;
case 104:
Serial.println("0");
break;
case 176:
Serial.println("C");
break;
case 48:
Serial.println("1");
break;
case 24:
Serial.println("2");
break;
case 122:
Serial.println("3");
break;
case 16:
Serial.println("4");
break;
case 56:
Serial.println("5");
break;
case 90:
Serial.println("6");
break;
case 66:
Serial.println("7");
break;
case 74:
Serial.println("8");
break;
case 82:
Serial.println("9");
break;
}
Serial.println("=======================");
irrecv.resume(); //准备接收下一个红外遥控指令
}
delay(100);
}