Created
June 7, 2015 11:47
-
-
Save kkmonster/d2592813ade7e3266b7f to your computer and use it in GitHub Desktop.
First test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#define daikin_freq 38 | |
#define daikin_data 27 | |
int count = 0; | |
byte delay_low = 0; | |
byte ir_byte_no = 0; | |
byte ir_header = 0; | |
byte ir_state = 0; | |
char IR_data[daikin_data] = {0x11,0xDA,0x27,0xF0,0x00,0x00,0x00,0x20, | |
//0 1 2 3 4 5 6 7 | |
0x11,0xDA,0x27,0x00,0x00,0x41,0x1E,0x00, | |
//8 9 10 11 12 13 14 15 | |
0xB0,0x00,0x00,0x00,0x00,0x00,0x00,0xC0,0x00,0x00,0xE3 }; | |
//16 17 18 19 20 21 22 23 24 25 26 | |
/* | |
byte 13=mode | |
b7 = 0 | |
b6+b5+b4 = Mode | |
b3 = 0 | |
b2 = OFF timer set | |
b1 = ON timer set | |
b0 = Air Conditioner ON | |
Modes: b6+b5+b4 | |
011 = Cool | |
100 = Heat (temp 23) | |
110 = FAN (temp not shown, but 25) | |
000 = Fully Automatic (temp 25) | |
010 = DRY (temp 0xc0 = 96 degrees c) | |
byte 14=temp*2 | |
byte 16=Fan | |
FAN control | |
b7+b6+b5+b4 = Fan speed | |
b3+b2+b1+b0 = Swing control up/down | |
Fan: b7+b6+b5+b4 | |
0×30 = 1 bar | |
0×40 = 2 bar | |
0×50 = 3 bar | |
0×60 = 4 bar | |
0×70 = 5 bar | |
0xa0 = Auto | |
0xb0 = Not auto, moon + tree | |
Swing control up/down: | |
0000 = Swing up/down off | |
1111 = Swing up/down on | |
Swing control left/right: | |
0000 = Swing left/right off | |
1111 = Swing left/right on | |
*/ | |
void setup() { | |
pinMode(1, OUTPUT); | |
digitalWrite(1, LOW); | |
sendDaikin(daikin_data); | |
} | |
void loop() { | |
delay (800); | |
sendDaikin(daikin_freq); | |
} | |
void sendDaikin(int khz) { | |
// Enables IR output. The khz value controls the modulation frequency in kilohertz. | |
delay_low = 1; | |
ir_byte_no = 0; | |
ir_header = 1; | |
timer1_isr_init(); | |
timer1_attachInterrupt(dataIROut); | |
timer1_enable(TIM_DIV1, TIM_EDGE, TIM_LOOP); | |
timer1_write(clockCyclesPerMicrosecond()*500 / khz); | |
} | |
void dataIROut() { | |
static byte resume_tmp; | |
static byte data_tmp; | |
static int j; | |
static int i; | |
static int temp; | |
static int temp_go_low; | |
static int pwm_enable; | |
if (resume_tmp){ | |
resume_tmp = 0; | |
delay_low = 0; | |
timer1_write(clockCyclesPerMicrosecond()*500 / daikin_freq); // 38khz | |
} | |
if (ir_header == 1){ | |
ir_header = 0; | |
j = 0; | |
i = 0; | |
pwm_enable = 1; | |
temp = 384; | |
temp_go_low = 256; | |
data_tmp = IR_data[ir_byte_no]; | |
} else { | |
if (i >= temp) | |
{ | |
i = 0; | |
if (data_tmp & (1 << j)){ | |
temp = 128; // High | |
} else { | |
temp = 64; // Low | |
} | |
pwm_enable = 1; | |
temp_go_low = 32; | |
if (j >= 8) { | |
j = 0; | |
ir_byte_no ++; | |
if (ir_byte_no == daikin_data){ | |
timer1_detachInterrupt(); | |
ir_state = 1; //IR off | |
} | |
data_tmp = IR_data[ir_byte_no]; | |
} | |
j++; | |
} | |
} | |
if (ir_byte_no == 8 && delay_low == 1){ | |
timer1_write(clockCyclesPerMicrosecond()*30000); // delay 30ms | |
resume_tmp = 1; //resume | |
ir_state = 1; //IR off | |
} | |
if(i >= temp_go_low) pwm_enable = 0; | |
if(pwm_enable ==1){ | |
ir_state = 1 - ir_state; | |
digitalWrite(1, ir_state); | |
} else { | |
ir_state = 0; | |
digitalWrite(1, ir_state); | |
} | |
i++ ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment