测试代码:
#include <IRremote.h>
int RECV_PIN=3; //定义引脚
IRrecv irrecv(RECV_PIN); //建立一个接受对象
decode_results results; //定义解码变量
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //打开串口
irrecv.enableIRIn(); //让定义的对象开始工作
}
void loop() {
// put your main code here, to run repeatedly:
if(irrecv.decode(&results)) {
Serial.println(results.value,DEC);
irrecv.resume();
}
delay(500);
}
加呼吸灯:
#include <IRremote.h>
#define RED 12
#define GREEN 11
#define BLUE 10
int RECV_PIN=3; //定义引脚
IRrecv irrecv(RECV_PIN); //建立一个接受对象
decode_results results; //定义解码变量
void Clear()
{
analogWrite(RED,255);
analogWrite(GREEN,255);
analogWrite(BLUE,255);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600); //打开串口
pinMode(12,OUTPUT);
pinMode(11,OUTPUT);
pinMode(10,OUTPUT);
irrecv.enableIRIn(); //让定义的对象开始工作
Clear();
}
void loop() {
// put your main code here, to run repeatedly:
if(irrecv.decode(&results))
{
Serial.println(results.value,DEC);
if(results.value==16738455) Clear();
else if(results.value==16724175){ Clear();analogWrite(RED,0);}
else if(results.value==16718055){ Clear();analogWrite(GREEN,0);}
else if(results.value==16743045){ Clear();analogWrite(BLUE,0);}
irrecv.resume();
}
//2=16718055
//3=16743045
//1=16724175
//0=16738455
delay(500);
}