米思齐遥控调光器
米思齐遥控调光器
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-来控制灯光的量度
暗
亮
米思齐效果图:
上一篇: 在米思齐上实现数码管图形化编程
下一篇: 第一章-随机变量与概率估计