目前在做一个手机控制格力空调的项目,手机端有app,通过蓝牙连接arduino ,事先使用IRremote库解码了格力空调YBOF2,现在的情况是没有反应,大神们给看看啊!
这是获取的原始码:8850 -4400 650 -550 650 -550 650 -1600 650 -1600 650 -1650 650 -500 650 -1600 700 -500 650 -1600 650 -1650 650 -500 700 -1600 650 -500 650 -550 650 -550 650 -550 650 -500 650 -550 650 -550 650 -500 650 -550 650 -1600 650 -550 650 -550 650 -500 650 -550 650 -550 650 -500 700 -1600 650 -500 650 -1650 650 -500 650 -550 650 -1600 650 -550 650
[mw_shl_code=c,true]#include <IRremote.h>
#define DHT11_PIN 0
byte dht11_dat[5];
int inByte, temp, direct,velo;
int temperature = 1;
int direction = 1;
int velocity = 1;
IRsend irsend;
unsigned int RawCodes_num1[73] = {4400,650,550,650,550,650,1600,650,1600,650,1600,650,1650,650,
1600,650,550,650,1600,650 ,550,650,500,650,1650,650,500,650,550,650,
550,650,500,650,550,650,550,600,600,650,500,650,550,650,1600,650,550,
650,550,600,550,650,550,650,550,650,500,650,1650,650,500,650,1650,650 ,
500,650,550,650,1600,650,550,650};
void setup()
{
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
Serial.begin(9600);
}
void loop()
{
while(1)
{
if(Serial.available() > 0)
{
inByte = Serial.read();
if(inByte = 73)
{
temp = Serial.read();
direct = Serial.read();
velo = Serial.read();
finally(temp,direct,velo);
}
}
delay(60000);
}
}
void DHT11()
{
byte dht11_in;
int i;
PORTC &= ~_BV(DHT11_PIN);
delay(18);
PORTC &= _BV(DHT11_PIN);
delayMicroseconds(40);
DDRC &= ~_BV(DHT11_PIN);
delayMicroseconds(40);
dht11_in = PINC & _BV(DHT11_PIN);
if(dht11_in)
{
Serial.println("dht11 response signal 1 not received");
return;
}
delayMicroseconds(80);
dht11_in = PINC & _BV(DHT11_PIN);
if(!dht11_in)
{
Serial.println("dht11 response signal 2 not received");
return;
}
delayMicroseconds(80);
for (i = 0; i<5;i++)
{
dht11_dat = read_dht11_dat();
}
byte dht11_check_sum = dht11_dat[0]+dht11_dat[1]+dht11_dat[2]+dht11_dat[3];
if(dht11_dat[4] != dht11_check_sum)
{
Serial.println("DHT11 checksum error");
}
DDRC |= _BV(DHT11_PIN);
PORTC |= _BV(DHT11_PIN);
}
byte read_dht11_dat()
{
int i =0;
byte result = 0;
for(i=0; i<8;i++)
{
while(!(PINC & _BV(DHT11_PIN)));
delayMicroseconds(30);
if(PINC & _BV(DHT11_PIN))
result |=(1<<(7-i));
while((PINC & _BV(DHT11_PIN)));
}
return result;
}
void finally (int m,int n,int t)
{
DHT11();
if(temperature!=m)
{
temperature=m;
switch(m)
{
case 2:
Serial.println("25 she shi du");
RawCodes_num1[18] = 1650;
RawCodes_num1[20] = 550;
RawCodes_num1[22] = 550;
RawCodes_num1[8] = 1650;
break;
case 3:
Serial.println("26 she shi du");
RawCodes_num1[18] = 550;
RawCodes_num1[20] = 1650;
RawCodes_num1[22] = 550;
RawCodes_num1[8] = 1650;
break;
case 4:
Serial.println("27 she shi du");
RawCodes_num1[18] = 1650;
RawCodes_num1[20] = 1650;
RawCodes_num1[22] = 550;
RawCodes_num1[8] = 1650;
break;
case 5:
Serial.println("guan ji");
RawCodes_num1[8] = 550;
break;
case 1:
default:
Serial.println("24 she shi du");
RawCodes_num1[18] = 550;
RawCodes_num1[20] = 550;
//RawCodes_num1[24] = 550;
RawCodes_num1[8] = 1650;
break;
}
if(dht11_dat[2]-23<m)
{
Serial.println("zhi re");
RawCodes_num1[2] = 650;
RawCodes_num1[6] = 1650;
// RawCodes_num1[79] = 1650;
// RawCodes_num1[81] = 550;
// RawCodes_num1[83] = 550;
}
else
{
Serial.println("zhi leng");
RawCodes_num1[2] = 1650;
RawCodes_num1[6] = 650;
// RawCodes_num1[79] = 1650;
// RawCodes_num1[81] = 550;
//RawCodes_num1[83] = 550;
}
irsend.sendRaw(RawCodes_num1,73,38);
}
if(direction!=n)
{
direction = n;
switch(n)
{
case 1:
Serial.println("Wind Direction 1");
RawCodes_num1[14] = 1650;
// RawCodes_num1[31] = 550;
// RawCodes_num1[33] = 1650;
break;
case 2:
Serial.println("Wind Direction 2");
RawCodes_num1[14] = 550;
// RawCodes_num1[31] = 1650;
// RawCodes_num1[33] = 550;
break;
/* case 3:
Serial.println("Wind Direction 3");
RawCodes_num1[29] = 550;
RawCodes_num1[31] = 1650;
RawCodes_num1[33] = 1650;
break;
case 4:
Serial.println("Wind Direction 4");
RawCodes_num1[29] = 1650;
RawCodes_num1[31] = 550;
RawCodes_num1[33] = 550;
break;
case 5:
Serial.println("Wind Direction 5");
RawCodes_num1[29] = 1650;
RawCodes_num1[31] = 550;
RawCodes_num1[33] = 1650;
break;
case 6: */
default:
Serial.println("no Wind Direction ");
RawCodes_num1[14] = 550;
//RawCodes_num1[31] = 1650;
// RawCodes_num1[33] = 550;
break;
}
if(dht11_dat[2]-23<m)
{
Serial.println("zhi re");
RawCodes_num1[2] = 550;
RawCodes_num1[6] = 1650;
//RawCodes_num1[79] = 1650;
// RawCodes_num1[81] = 1650;
// RawCodes_num1[83] = 550;
}
else
{
Serial.println("zhi leng");
RawCodes_num1[2] = 1650;
RawCodes_num1[6] = 550;
//RawCodes_num1[79] = 1650;
// RawCodes_num1[81] = 550;
// RawCodes_num1[83] = 1650;
}
irsend.sendRaw(RawCodes_num1,73,38);
}
if(velocity!=t)
{
velocity = t;
switch(t)
{
case 1:
Serial.println("Wind Velocity 1");
RawCodes_num1[10] = 1650;
RawCodes_num1[12] = 550;
//RawCodes_num1[89] = 1650;
break;
case 2:
Serial.println("Wind Velocity 2");
RawCodes_num1[10] = 550;
RawCodes_num1[12] = 1650;
// RawCodes_num1[89] = 550;
break;
case 3:
Serial.println("Wind Velocity 3");
RawCodes_num1[10] = 1650;
RawCodes_num1[12] = 1650;
//RawCodes_num1[89] = 1650;
break;
case 4:
default:
Serial.println("Wind Velocity auto");
RawCodes_num1[10] = 550;
RawCodes_num1[12] = 550;
//RawCodes_num1[33] = 1650;
break;
}
if(dht11_dat[2]-23<m)
{
Serial.println("zhi re");
RawCodes_num1[2] = 550;
RawCodes_num1[6] = 1650;
//RawCodes_num1[79] = 550;
// RawCodes_num1[81] = 550;
// RawCodes_num1[83] = 550;
}
else
{
Serial.println("zhi leng");
RawCodes_num1[2] = 1650;
RawCodes_num1[6] = 550;
//RawCodes_num1[79] = 1650;
// RawCodes_num1[81] = 1650;
// RawCodes_num1[83] = 1650;
}
irsend.sendRaw(RawCodes_num1,73,38);
}
}[/mw_shl_code] |