Mixly遥控器调节LED灯亮度

通过遥控器调节LED灯亮度

一、实验目的及要求

按遥控器上的CH键实现LED的开关。开了LED的情况下可以通过CH+和CH-键实现控制LED的光亮变化。LED关闭状态CH+和CH-无效

二、实验软硬件环境

硬件:Arduino、红外遥控传感器、遥控器
软件:MixlyIDE

图形界面编码:
Mixly遥控器调节LED灯亮度_第1张图片
c代码:

#include 
IRrecv irrecv_6(6);
decode_results results_6;
long ir_item;
volatile int led;
volatile boolean ledState;
void setup(){
  led= 0;
ledState = 0;
Serial.begin(9600);
irrecv_6.enableIRIn();
}
void loop(){
  if
(irrecv_6.decode(&results_6)) {
ir_item=results_6.value;
String type="UNKNOWN";
String typelist[14]={"UNKNOWN", "NEC",
"SONY", "RC5", "RC6", "DISH",
"SHARP", "PANASONIC", "JVC", "SANYO", "MITSUBISHI",
"SAMSUNG", "LG", "WHYNTER"};
if(results_6.decode_type>=1&&results_6.decode_type<=13){
 type=typelist[results_6.decode_type];
     }   
Serial.print("IR TYPE:"+type+"  ");
Serial.println(ir_item,HEX);
if (ir_item == 0XFF629D) {
ledState = !ledState;
led = ledState * 128;
    }
   if (ledState == 1) {
     if (ir_item == 0XFFA25D) {
       led = constrain(led - 20, 0, 255);
   }
if (ir_item == 0XFFE21D) {
       led = constrain(led + 20, 0, 255);
       }
    }   
analogWrite(10,led);
Serial.println(led);
irrecv_6.resume();
  }
else {
  } 
}

效果:

遥控器调节LED灯亮度

你可能感兴趣的:(Mixly遥控器调节LED灯亮度)