|
楼主 |
发表于 2013-11-12 10:51:39
|
显示全部楼层
本帖最后由 Gemicio 于 2013-11-12 23:01 编辑
三、Arduino控制红外遥控信号和继电器
OpenWrt通过串口发送给Arduino每次两个字符,第一个字符ch1选择电器,第二个字符ch2选择遥控功能
Arduino mini -pro的4567四个引脚控制四路继电器,IRremote.h编码红外遥控信号 - #include <IRremote.h>;
- IRsend irsend;
- unsigned int flpMenu[] = {1800, 850, 900, 800, 900, 850, 950, 800, 900, 850, 900, 850, 850, 850, 950, 1600, 1850, 850, 900, 1700, 1800, 23164};
- #define led4 4
- #define led5 5
- #define led6 6
- #define led7 7
- int Av0=2;
- int Av1=1;
复制代码
IRremote不能解码的遥控信号只能用raw格式,在这里定义。AV0\1用来设置电视机视频输入源,实现一键选择
[pre lang="arduino" line="462"] case 'P': // Select TV AV in
switch(ch2){
case '1':
{
Av1=1; //TV
}
break;
case '2':
{
Av1=2; //HDIMI1
}
break;
case '3':
{
Av1=3; //HDMI2
}
break;
case '4':
{
Av1=4; //CVI1
}
break;
case '5':
{
Av1=5; //CVI2
}
break;
case '6':
{
Av1=6; //AV
}
break;
case '7':
{
Av1=7; //Side AV
}
case '8':
{
Av1=8; //PC VGA
}
break;
}
irsend.sendRC5(0x838, 12); // PHILIPS TV AV
delay(600);
if (Av1>=Av0){
for (int i=Av0; i<=Av1; i++)
{
irsend.sendRC5(0x838, 12); // PHILIPS TV AV
delay(100);
if (i<Av1){
irsend.sendRC5(0x038, 12); // PHILIPS TV AV
delay(200);
i++;
}
}
}
else {
for (int i=Av0; i<=Av1+8; i++)
{
irsend.sendRC5(0x838, 12); // PHILIPS TV AV
delay(100);
if (i<Av1+8){
irsend.sendRC5(0x038, 12); // PHILIPS TV AV
delay(200);
i++;
}
}
}
for (int i = 0; i < 2; i++) {
irsend.sendRaw(flpOk, 22, 38); //PHILIPS TV ok
delay(100);
}
Av0=Av1;
break;[/code]
飞利浦的遥控信号居然连续两次按是不一样的,想了半天用了这个办法好歹解决了’一键选择‘
继电器控制很简单,如果打开就关闭,如果关闭就打开:
[pre lang="arduino" line="539"]case 'X': // AC POWER
switch(ch2){
case '1':
if (digitalRead(led4) == HIGH){
digitalWrite(led4,LOW);
}
else{
digitalWrite(led4,HIGH);
}
break;
case '2':
if (digitalRead(led5) == HIGH){
digitalWrite(led5,LOW);
}
else{
digitalWrite(led5,HIGH);
}
break;[/code] |
|