实现米思齐按键控制LED
代码实现如下:
#include <IRremote.h>
IRrecv irrecv_10(10);
decode_results results_10;
long ir_value;
volatile int led;
volatile boolean ledstate;
void setup(){
Serial.begin(9600);
irrecv_10.enableIRIn();
led = 0;
ledstate = 0;
}
void loop(){
if (irrecv_10.decode(&results_10)) {
ir_value=results_10.value;
String type="UNKNOWN";
String typelist[14]={"UNKNOWN", "NEC", "SONY", "RC5", "RC6", "DISH", "SHARP", "PANASONIC", "JVC", "SANYO", "MITSUBISHI", "SAMSUNG", "LG", "WHYNTER"};
if(results_10.decode_type>=1&&results_10.decode_type<=13){
type=typelist[results_10.decode_type];
}
Serial.print("IR TYPE:"+type+" ");
Serial.println(ir_value,HEX);
if (ir_value == 0xFF629D) {
ledstate = !ledstate;
led = ledstate * 128;
}
if (1 == ledstate) {
if (ir_value == 0xFFE21D) {
led = constrain(led + 20, 0, 255);
} else if (ir_value == 0xFFA25D) {
led = constrain(led - 20, 0, 255);
}
Serial.println(led);
analogWrite(6,led);
}
irrecv_10.resume();
} else {
}
}
来源:https://blog.csdn.net/Amouzy/article/details/102748439