由于美的空调使用的不是简单的红外编码信号,因此在使用arduino红外库的时候不能直接调用其已有的编码规则,需要先了解美的空调的编码规则,再使用IRsend::sendRaw这个函数直接发送原始数据。本文建立在已经对红外发送有了了解并且搜到了美的空调的编码规则的基础上(编码规则在百度即可搜到https://wenku.baidu.com/view/c46594141ed9ad51f01df2c3.html)
一、编码规则
根据美的的编码规则,L A A' B B' C C' S L A A' B B' C C' O为最普通的开机码,其中L为引导码,A、B、C为决定温度,风速,模式的码,A',B',C'分别为A,B,C按位取反后的码,S为分隔码,O为终止码(均可在上面的链接上查到)
关机码与开机码稍有不同,如果想直接关机,可以直接复制下面的数组buf[300]
{4400,4400,
550,1660,550,550,550,1660,550,1660,550,550,550,550,550,1660,550,550,
550,550,550,1660,550,550,550,550,550,1660,550,1660,550,550,550,1660,
550,550,550,1660,550,1660,550,1660,550,1660,550,550,550,1660,550,1660,
550,1660,550,550,550,550,550,550,550,550,550,1660,550,550,550,550,
550,1660,550,1660,550,1660,550,550,550,550,550,550,550,550,550,550,
550,550,550,550,550,550,550,1660,550,1660,550,1660,550,1660,550,1660,
550,5220,
4400,4400,
550,1660,550,550,550,1660,550,1660,550,550,550,550,550,1660,550,550,
550,550,550,1660,550,550,550,550,550,1660,550,1660,550,550,550,1660,
550,550,550,1660,550,1660,550,1660,550,1660,550,550,550,1660,550,1660,
550,1660,550,550,550,550,550,550,550,550,550,1660,550,550,550,550,
550,1660,550,1660,550,1660,550,550,550,550,550,550,550,550,550,550,
550,550,550,550,550,550,550,1660,550,1660,550,1660,550,1660,550,1660,
550,5220,
4400,4400,
550,1660,550,550,550,1660,550,1660,550,550,550,550,550,1660,550,550,
550,550,550,1660,550,550,550,550,550,1660,550,1660,550,550,550,1660,
550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,
550,1660,550,1660,550,1660,550,1660,550,1660,550,1660,550,1660,550,1660,
550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,550,
550,1660,550,1660,550,1660,550,1660,550,1660,550,1660,550,1660,550,1660,
550,8000};
二、解码函数
如果要把每一个码都直接存起来就有点浪费内存了,其实可变的码也就A,B,C这三个字节,下面的函数实现了输入三个字节A,B,C,就把全局数组buf[200]用持续时间填满,之后直接使用sendRaw(buf,200,38)就可以开机并设置温度,风速,模式了。
void getcode(unsigned char A,unsigned char B,unsigned char C){
unsigned char mask=0x80;
unsigned int cnt=2;
buf[0]=4400;
buf[1]=4400;
//发A
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & A)
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & (~A))
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
//发B
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & B)
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & (~B))
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
//发C
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & C)
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & (~C))
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
buf[cnt++]=550;
buf[cnt++]=5220;
buf[cnt++]=4400;
buf[cnt++]=4400;
//发A
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & A)
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & (~A))
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
//发B
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & B)
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & (~B))
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
//发C
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & C)
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
for(mask=0x80;mask!=0;mask>>=1){
buf[cnt++]=550;
if(mask & (~C))
buf[cnt++]=1660;
else
buf[cnt++]=550;
}
buf[cnt++]=550;
buf[cnt++]=8800;
}
转载自原文链接, 如需删除请联系管理员。
原文链接:利用arduino红外库遥控美的家用空调,转载请注明来源!