#include <IRremote.h>

int RECV_PIN = 6;
int TEST_PIN = 8;
int BUTTON_PIN = 9;
int STATUS_PIN = 7;

IRrecv irrecv(RECV_PIN);
IRsend irsend;

decode_results results;

//LG 에어컨에서 자주 사용하는 적외선 코드. 메모리가 부족하면 최적화할 것.
unsigned int PowerOn[] = {8350,4000,400,1550,400,600,350,600,400,550,400,1550,400,600,350,600,400,600,350,600,400,600,350,600,400,600,350,600,400,550,400,600,350,600,400,1550,400,600,350,600,400,600,350,600,400,1550,400,600,350,600,400,1550,350,1600,350,600,400,600,350};
unsigned int PowerOff[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,1550,350,1600,350,600,400,600,350,600,400,600,350,600,400,550,400,600,350,600,400,600,350,600,400,600,350,1600,350,600,400,1550,350,600,400,600,350,600,400,1550,400};
unsigned int PowerMode[] = {8300,4000,400,1600,350,600,400,600,350,600,350,1600,350,600,400,600,350,600,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,600,350,600,350,600,400,1550,400,600,350,600,400,1550,400};
unsigned int t18w1[] = {8300,4000,400,1550,400,550,400,600,350,600,400,1550,400,600,350,600,400,600,350,600,400,550,400,600,400,550,400,1550,400,600,400,550,400,600,350,600,400,600,350,1600,350,1550,400,600,350,600,400,600,350,600,400,1550,400,600,350,1550,400,1550,400};
unsigned int t18w2[] = {8350,4000,400,1550,400,600,350,600,350,600,400,1550,400,600,350,600,400,600,350,600,400,550,400,600,400,550,400,1550,400,600,350,600,400,600,350,600,400,600,350,1600,350,1550,400,600,350,600,400,1550,400,600,350,1600,350,1550,400,600,400,1550,350};
unsigned int t18w3[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,550,400,600,400,1550,400,1550,350,600,400,1550,400,550,400,600,400,1550,400,1550,350,1600,350,1600,350};
unsigned int t19w1[] = {8350,3950,400,1600,350,600,400,600,350,600,400,1550,400,550,400,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,600,350,600,400,550,400,600,400,1550,350,600,400,600,350,600,400,600,350,600,400,600,350,1550,400,1550,400,600,350,600,400};
unsigned int t19w2[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,550,400,600,400,550,400,600,350,1600,350,600,400,600,350,600,400,600,350,1550,400,600,400,550,400,600,350,600,400,1550,400,600,350,1550,400,1550,400,1550,400,600,350};
unsigned int t19w3[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1550,400,600,400,550,400,600,350,600,400,600,350,600,400,600,350,1600,350,600,400,550,400,600,400,550,400,1550,400,600,350,600,400,600,350,1550,400,600,400,550,400,600,400,550,400,600,350,600,400};
unsigned int t20w1[] = {8300,4000,400,1600,350,600,400,600,350,600,400,1550,350,600,400,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,550,400,600,400,550,400,600,350,1600,350,600,400,1550,400,600,350,600,400,550,400,600,400,1550,350,1600,350,600,400,1550,400};
unsigned int t20w2[] = {8300,4000,400,1600,350,600,400,600,350,600,400,1550,400,550,400,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,550,400,600,350,600,400,600,350,1600,350,600,400,1550,400,600,350,600,400,1550,400,550,400,1550,400,1550,400,1550,400,1550,400};
unsigned int t20w3[] = {8300,4000,400,1600,350,600,400,600,350,600,400,1550,400,550,400,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,550,400,600,350,600,400,600,400,1550,350,1600,350,600,400,600,350,1550,400,600,350,600,400,600,350,600,400,1550,400,600,350};
unsigned int t21w1[] = {8800,3950,400,1600,350,600,400,600,350,600,400,1550,350,650,350,600,400,550,400,600,350,600,400,600,350,600,400,1550,400,600,350,600,400,550,400,600,350,1600,350,1600,350,600,400,550,400,600,400,600,350,600,350,1600,350,1600,350,1600,350,600,400};
unsigned int t21w2[] = {8350,3950,400,1600,350,600,400,600,350,600,400,1550,400,600,350,600,400,600,350,600,400,550,400,600,350,600,400,1550,400,600,350,600,400,600,350,600,400,1550,350,1600,350,600,400,600,350,600,400,1550,400,600,350,600,400,550,400,600,350,600,400};
unsigned int t21w3[] = {8350,3950,400,1600,400,550,400,600,350,600,400,1550,400,600,350,600,400,550,400,600,400,550,400,600,350,600,400,1550,400,600,350,600,400,600,350,600,400,1550,400,1550,350,1600,350,600,400,1550,400,600,350,600,400,550,400,600,400,1550,400,1550,350};
unsigned int t22w1[] = {8300,4000,400,1600,350,600,400,600,350,600,400,1550,350,600,400,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,550,400,600,350,600,400,600,350,1600,350,1600,350,1600,350,600,400,600,350,600,400,550,400,1550,400,1550,400,1550,400,1550,400};
unsigned int t22w2[] = {8300,4000,400,1600,350,600,400,600,350,600,400,1550,350,650,350,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,600,350,600,400,550,400,600,350,1600,350,1600,350,1550,400,600,400,550,400,1550,400,600,350,600,400,600,350,600,400,1550,400};
unsigned int t22w3[] = {8350,3950,400,1600,350,600,400,600,350,600,400,1550,350,600,400,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,550,400,600,350,600,400,1550,400,600,350,600,400,600,350,600,400,1550,400,550,400,600,400,550,400,1550,400,600,350,600,400};
unsigned int t23w1[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1550,400,600,350,600,400,600,350,600,400,600,350,600,400,600,350,1550,400,600,400,550,400,600,350,1600,350,600,400,600,350,600,400,600,350,600,400,600,350,600,400,550,400,600,350,600,400,600,350};
unsigned int t23w2[] = {8350,3950,400,1600,350,600,400,600,350,600,400,1550,400,550,400,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,550,400,600,400,550,400,1550,400,600,350,600,400,600,350,600,400,600,350,1550,400,600,400,550,400,600,400,1550,350,600,400};
unsigned int t23w3[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,550,400,600,400,550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,1550,400,600,350,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,1550,400,600,350,600,350};
unsigned int t24w1[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,1550,400,550,400,600,350,1600,350,600,400,600,350,600,400,600,350,600,400,550,400,600,400,1550,350};
unsigned int t24w2[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,550,400,600,400,550,400,600,350,1600,350,600,400,600,350,600,400,1550,400,550,400,600,350,1600,350,600,400,600,350,1600,350,600,400,550,400,600,400,1550,350,1600,350};
unsigned int t24w3[] = {8350,4000,400,1550,350,600,400,600,400,550,400,1550,400,600,350,600,400,600,350,600,400,600,350,600,400,550,400,1550,400,600,350,600,400,600,350,1600,350,600,400,600,350,1550,400,600,400,1550,350,600,400,600,350,600,400,1550,400,600,350,1550,400};
unsigned int t25w1[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,550,400,600,400,550,400,600,400,550,400,600,350,1600,350,600,400,600,350,600,400,1550,400,550,400,1550,400,600,350,600,400,600,350,600,400,600,350,600,400,600,350,1550,400,600,400};
unsigned int t25w2[] = {8300,4000,400,1550,350,600,400,600,350,600,400,1550,400,600,350,600,400,600,350,600,400,600,350,600,350,600,400,1550,400,600,350,600,400,600,350,1600,350,600,400,1550,400,550,400,600,350,600,400,1550,400,600,350,600,400,1550,400,600,350,600,350};
unsigned int t25w3[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,600,350,600,400,550,400,600,350,1600,350,600,400,600,350,600,400,1550,400,600,350,1600,350,600,350,600,400,1550,400,600,350,600,400,600,350,1550,400,1550,400,600,350};
unsigned int t26w1[] = {8300,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,600,350,600,350,600,400,600,400,1550,350,600,400,600,350,600,400,1550,400,550,400,1550,400,1550,400,600,350,600,400,600,350,600,400,600,350,600,400,1550,400,1550,350};
unsigned int t26w2[] = {8350,4000,400,1550,400,600,350,600,400,600,350,1600,350,600,400,550,400,600,350,600,400,600,350,600,400,600,350,1600,350,600,400,600,350,600,400,1550,350,600,400,1550,400,1550,400,600,350,600,400,1550,400,600,350,600,350,1600,350,600,400,1550,400};
unsigned int t26w3[] = {8350,4000,400,1550,400,600,350,600,400,600,350,1550,400,600,350,600,400,600,350,600,400,600,350,600,400,600,350,1600,350,600,400,550,400,600,350,1600,350,600,400,1550,400,1550,400,600,350,1600,350,600,350,600,400,600,350,1600,350,1600,350,1600,350};



void setup()
{
  Serial.begin(9600);
  irrecv.enableIRIn(); // 수신기를 실행한다.
  pinMode(BUTTON_PIN, INPUT_PULLUP); //제1 스위치
  pinMode(TEST_PIN, INPUT_PULLUP); //제2 스위치
  pinMode(STATUS_PIN, OUTPUT);
}

#define SWITCH(w,t) switch(w + t<<2)
#define CASE(w,t) case(w + t<<2)
int wind = 3;
int temp = 18;
boolean powerState = 0;

void ACCode(int w, int t) {
  SWITCH(w,t){
    CASE(3,18):
    sendCode(t18w3, 59);
    break;

    CASE(3,19):
    sendCode(t19w3, 59);
    break;

    CASE(3,20):
    sendCode(t20w3, 59);
    break;

    CASE(3,21):
    sendCode(t21w3, 59);
    break;

    CASE(3,22):
    sendCode(t22w3, 59);
    break;

    CASE(3,23):
    sendCode(t23w3, 59);
    break;

    CASE(3,24):
    sendCode(t24w3, 59);
    break;

    CASE(3,25):
    sendCode(t25w3, 59);
    break;

    CASE(3,26):
    sendCode(t26w3, 59);
    break;

    CASE(1,18):
    sendCode(t18w1, 59);
    break;

    CASE(1,19):
    sendCode(t19w1, 59);
    break;

    CASE(1,20):
    sendCode(t20w1, 59);
    break;

    CASE(1,21):
    sendCode(t21w1, 59);
    break;

    CASE(1,22):
    sendCode(t22w1, 59);
    break;

    CASE(1,23):
    sendCode(t23w1, 59);
    break;

    CASE(1,24):
    sendCode(t24w1, 59);
    break;

    CASE(1,25):
    sendCode(t25w1, 59);
    break;

    CASE(1,26):
    sendCode(t26w1, 59);
    break;

    CASE(2,18):
    sendCode(t18w2, 59);
    break;

    CASE(2,19):
    sendCode(t19w2, 59);
    break;

    CASE(2,20):
    sendCode(t20w2, 59);
    break;

    CASE(2,21):
    sendCode(t21w2, 59);
    break;

    CASE(2,22):
    sendCode(t22w2, 59);
    break;

    CASE(2,23):
    sendCode(t23w2, 59);
    break;

    CASE(2,24):
    sendCode(t24w2, 59);
    break;

    CASE(2,25):
    sendCode(t25w2, 59);
    break;

    CASE(2,26):
    sendCode(t26w3, 59);
    break;
   
  }
}

void sendCode(unsigned int rawCodes[], int codeLen)
{
  digitalWrite(STATUS_PIN, HIGH);
  irsend.sendRaw(rawCodes, codeLen, 38);
  digitalWrite(STATUS_PIN, LOW);
}

void loop()
{
  if (irrecv.decode(&results)) {
    Serial.println(results.value, HEX);
    delay(500); //avoid mixing signal
    switch(results.value) {
      case 0xFFC23D: //power on, off
      if(powerState == 0)
        {sendCode(PowerOn, 59); powerState = 1;}
        else
        {sendCode(PowerOff, 59); powerState = 0;}
      break;

      case 0xFF906F:
        sendCode(PowerMode,59); //Power Mode
        break;
     
      case 0xFF02FD: //wind up
        if(wind<3)
          {wind++;}
          else
          {wind=1;}
        ACCode(wind, temp);
      break;

      case 0xFFA857: //temp up
        if(temp<26)
          {temp++;}
          else
          {temp=18;}
        ACCode(wind, temp);
      break;

      case 0xFFE01F: //temp down
        if(temp>18)
          {temp--;}
          else
          {temp=26;}
        ACCode(wind, temp);
      break;
    }
    irrecv.enableIRIn(); // 다음 신호 수신
  }
  /* 테스트용 온도 올리기 코드
  if(!digitalRead(TEST_PIN)) {
    while(!digitalRead(TEST_PIN)) {}
    temp++;
    Serial.print("increased temp to: ");Serial.println(temp);
   
  }
  if(!digitalRead(BUTTON_PIN)){
    while(!digitalRead(BUTTON_PIN)){}
    ACCode(wind, temp, cloc);
  }
  */
}

신고

'DATA > 열린 자료' 카테고리의 다른 글

츄님 보여줄 코드  (0) 2015.09.03
Take on Mars 사진  (0) 2015.07.08
그림자료: 환영합니다!  (2) 2013.02.28
4275Station 성능 및 속성 저장  (0) 2012.02.15
Posted by .라희

댓글을 달아 주세요