欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

mixly实现遥控器控制led

程序员文章站 2022-07-04 12:22:43
...

#实验目的:按遥控器上的CH键实现LED的开关。开了LED的情况下可以通过CH+和CH-键实现控制LED的光亮变化。LED关闭状态CH+和CH-无效。
硬件:Arduino、红外遥控传感器、遥控器
软件:Mixly IDE

##编程块:
mixly实现遥控器控制led

###代码:
#include <IRremote.h>

IRrecv irrecv_9(9);
decode_results results_9;

long ir_item;
volatile int led;
volatile boolean ledstate;

void setup(){
led = 0;
ledstate = 0;
pinMode(6, OUTPUT);
Serial.begin(9600);
irrecv_9.enableIRIn();
}

void loop(){
digitalWrite(6,LOW);
if (irrecv_9.decode(&results_9)) {
ir_item=results_9.value;
String type=“UNKNOWN”;
String typelist[14]={“UNKNOWN”, “NEC”, “SONY”, “RC5”, “RC6”, “DISH”, “SHARP”, “PANASONIC”, “JVC”, “SANYO”, “MITSUBISHI”, “SAMSUNG”, “LG”, “WHYNTER”};
if(results_9.decode_type>=1&&results_9.decode_type<=13){
type=typelist[results_9.decode_type];
}
Serial.print(“IR TYPE:”+type+" ");
digitalWrite(6,(!digitalRead(6)));
if (ir_value == 0xFF629D) {
ledstate = !ledstate;
led = ledstate * 128;

}
if (false) {
  if (ir_value == 0xFFA25D) {
    led = constrain(led - 20, 0, 255);

  }
  if (ir_value == 0xFFE21D) {
    led = constrain(led + 20, 0, 255);

  }

}
Serial.println(ir_item,HEX);
analogWrite(6,led);
irrecv_9.resume();

} else {
}

}