|
|
- #include <SoftwareSerial.h>
- //Infrared communation infomation
- byte InfrInitStart[]={0xAA,0xAA,0x08,0x08,0x00};
- byte InfrInitEnd[]={0xCC,0xCC,0x08,0x08,0x00};
- byte AirConVerion[]={0x02,0x00,0x2C,0x08,0x26};
- //fit the air condition type code 0x2C is 044 (meidi KFR-72LW)
- //if you want to control another air condition , you should change 0x2c
- byte AirConTrunOn[]={0x04,0xff,0x08,0x08,0xfb};
- byte AirConTurnOff[]={0x04,0x00,0x08,0x08,0x04};
- //use pin 6 as receivepin and use pin as transmitpin
- SoftwareSerial serial(6,7);
- void setup() {
- // put your setup code here, to run once:
- serial.begin(9600);
- Serial.begin(9600);
- Serial.println("use softserial");
-
- delay(1000);
- //Initialize the infrared mode start
- serial.write(InfrInitStart,5);
- if(checkRespondeCode())
- {
- //Initialize the infread mode end
- serial.write(InfrInitEnd,5);
- }
- else
- {
- exit(0);
- }
- if(checkRespondeCode())
- {
- //set the air condition mode version
- serial.write(AirConVerion,5);
- }
- else
- {
- exit(1);
- }
- if(checkRespondeCode()==false)
- {
- exit(2);
- }
-
-
- }
- void loop() {
- // put your main code here, to run repeatedly:
- delay(5000);
- //turn on the air condition
- serial.write(AirConTrunOn,5);
- Serial.println("0x04,0xff,0x08,0x08,0xfb");
- //turn off the air condition
- delay(5000);
- serial.write(AirConTurnOff,5);
- Serial.println("0x04,0x00,0x08,0x08,0x04");
- while(true)
- {}
- }
- boolean checkRespondeCode()
- {
- byte RXData;
- delay(1000);
- //Serial.println("check response code");
- if(serial.available())
- {
- delay(200);
- RXData=serial.read();
- //Serial.println(RXData,HEX);
- if(RXData==0x89)
- {
- //serial.println();
- Serial.println("xiang ying 89");
- return true;
- }
- else
- {
- Serial.println(RXData,HEX);
- }
- }
- Serial.println("no xiang ying");
- return false;
- }
复制代码
以上是代码,实验成功。有问题的可以询问 |
|