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

米思齐遥控调光器

程序员文章站 2024-03-25 21:14:28
...

米思齐遥控调光器

1.遥控实验一
代码如下:
#include <IRremote.h>

IRrecv irrecv_5(5);
decode_results results_5;

long ir_item;

void setup(){
Serial.begin(9600);
pinMode(10, OUTPUT);
irrecv_5.enableIRIn();
}

void loop(){
if (irrecv_5.decode(&results_5)) {
ir_item=results_5.value;
String type=“UNKNOWN”;
String typelist[14]={“UNKNOWN”, “NEC”, “SONY”, “RC5”, “RC6”, “DISH”, “SHARP”, “PANASONIC”, “JVC”, “SANYO”, “MITSUBISHI”, “SAMSUNG”, “LG”, “WHYNTER”};
if(results_5.decode_type>=1&&results_5.decode_type<=13){
type=typelist[results_5.decode_type];
}
Serial.print(“IR TYPE:”+type+" ");
Serial.println(ir_item,HEX);
digitalWrite(10,(!digitalRead(10)));
irrecv_5.resume();
} else {
}

}
实验图:
米思齐遥控调光器
米思齐实现效果图如下图所示:
米思齐遥控调光器
2.遥控实验二
代码如下:
#include <IRremote.h>

long CH;
IRrecv irrecv_5(5);
decode_results results_5;

volatile int led;
volatile int ledstate;

void setup(){
led = 0;
ledstate = 0;
Serial.begin(9600);
irrecv_5.enableIRIn();
}

void loop(){
if (irrecv_5.decode(&results_5)) {
CH=results_5.value;
String type=“UNKNOWN”;
String typelist[14]={“UNKNOWN”, “NEC”, “SONY”, “RC5”, “RC6”, “DISH”, “SHARP”, “PANASONIC”, “JVC”, “SANYO”, “MITSUBISHI”, “SAMSUNG”, “LG”, “WHYNTER”};
if(results_5.decode_type>=1&&results_5.decode_type<=13){
type=typelist[results_5.decode_type];
}
Serial.print(“IR TYPE:”+type+" ");
Serial.println(CH,HEX);
if (CH == 0XFF629D) {
ledstate = !ledstate;
led = ledstate * 128;

}
analogWrite(10,led);
if (CH == 0XFFE21D) {
  led = constrain(led + 100, 0, 255);
  analogWrite(10,led);

}
if (CH == 0XFFA25D) {
  led = constrain(led - 100, 0, 255);
  analogWrite(10,led);

}
irrecv_5.resume();

} else {
}

}
找出:
CH:FF629D
CH- FFA25D
CH+ FFE21D

实验图:
实现通过按钮CH,CH+,CH-来控制灯光的量度

米思齐遥控调光器

米思齐遥控调光器
米思齐效果图:
米思齐遥控调光器

相关标签: 米思齐