8000 Merge pull request #203 from chaeplin/LG_AC · AKrduino/Arduino-IRremote@77fd51e · GitHub
[go: up one dir, main page]

Skip to content

Commit 77fd51e

Browse files
committed
Merge pull request Arduino-IRremote#203 from chaeplin/LG_AC
adding SEND_LG
2 parents 22e64f1 + ec37148 commit 77fd51e

File tree

4 files changed

+312
-2
lines changed

4 files changed

+312
-2
lines changed

IRremote.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#define SEND_AIWA_RC_T501 1
5757

5858
#define DECODE_LG 1
59-
#define SEND_LG 0 // NOT WRITTEN
59+
#define SEND_LG 1
6060

6161
#define DECODE_SANYO 1
6262
#define SEND_SANYO 0 // NOT WRITTEN
@@ -300,7 +300,7 @@ class IRsend
300300
# endif
301301
//......................................................................
302302
# if SEND_LG
303-
void sendLG ( ) ; // NOT WRITTEN
303+
void sendLG (unsigned long data, int nbits) ;
304304
# endif
305305
//......................................................................
306306
# if SEND_SANYO
Lines changed: 249 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,249 @@
1+
#include <IRremote.h>
2+
#include <Wire.h>
3+
4+
5+
IRsend irsend;
6+
// not used
7+
int RECV_PIN = 11;
8+
IRrecv irrecv (RECV_PIN);
9+
10+
const int AC_TYPE = 0;
11+
// 0 : TOWER
12+
// 1 : WALL
13+
14+
int AC_POWER_ON = 0;
15+
// 0 : off
16+
// 1 : on
17+
18+
int AC_AIR_ACLEAN = 0;
19+
// 0 : off
20+
// 1 : on --> power on
21+
22+
int AC_TEMPERATURE = 27;
23+
// temperature : 18 ~ 30
24+
25+
int AC_FLOW = 1;
26+
// 0 : low
27+
// 1 : mid
28+
// 2 : high
29+
// if AC_TYPE =1, 3 : change
30+
31+
const int AC_FLOW_TOWER[3] = {0, 4, 6};
32+
const int AC_FLOW_WALL[4] = {0, 2, 4, 5};
33+
34+
unsigned long AC_CODE_TO_SEND;
35+
36+
int r = LOW;
37+
int o_r = LOW;
38+
39+
byte a, b;
40+
41+
void ac_send_code(unsigned long code)
42+
{
43+
Serial.print("code to send : ");
44+
Serial.print(code, BIN);
45+
Serial.print(" : ");
46+
Serial.println(code, HEX);
47+
48+
irsend.sendLG(code, 28);
49+
}
50+
51+
void ac_activate(int temperature, int air_flow)
52+
{
53+
54+
int AC_MSBITS1 = 8;
55+
int AC_MSBITS2 = 8;
56+
int AC_MSBITS3 = 0;
57+
int AC_MSBITS4 = 0;
58+
int AC_MSBITS5 = temperature - 15;
59+
int AC_MSBITS6 ;
60+
61+
if ( AC_TYPE == 0) {
62+
AC_MSBITS6 = AC_FLOW_TOWER[air_flow];
63+
} else {
64+
AC_MSBITS6 = AC_FLOW_WALL[air_flow];
65+
}
66+
67+
int AC_MSBITS7 = (AC_MSBITS3 + AC_MSBITS4 + AC_MSBITS5 + AC_MSBITS6) & B00001111;
68+
69+
AC_CODE_TO_SEND = AC_MSBITS1 << 4 ;
70+
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS2) << 4;
71+
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS3) << 4;
72+
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS4) << 4;
73+
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS5) << 4;
74+
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS6) << 4;
75+
AC_CODE_TO_SEND = (AC_CODE_TO_SEND + AC_MSBITS7);
76+
77+
ac_send_code(AC_CODE_TO_SEND);
78+
79+
AC_POWER_ON = 1;
80+
AC_TEMPERATURE = temperature;
81+
AC_FLOW = air_flow;
82+
}
83+
84+
void ac_change_air_swing(int air_swing)
85+
{
86+
if ( AC_TYPE == 0) {
87+
if ( air_swing == 1) {
88+
AC_CODE_TO_SEND = 0x881316B;
89+
} else {
90+
AC_CODE_TO_SEND = 0x881317C;
91+
}
92+
} else {
93+
if ( air_swing == 1) {
94+
AC_CODE_TO_SEND = 0x8813149;
95+
} else {
96+
AC_CODE_TO_SEND = 0x881315A;
97+
}
98+
}
99+
100+
ac_send_code(AC_CODE_TO_SEND);
101+
}
102+
103+
void ac_power_down()
104+
{
105+
AC_CODE_TO_SEND = 0x88C0051;
106+
107+
ac_send_code(AC_CODE_TO_SEND);
108+
109+
AC_POWER_ON = 0;
110+
}
111+
112+
void ac_air_clean(int air_clean)
113+
{
114+
if ( air_clean == 1) {
115+
AC_CODE_TO_SEND = 0x88C000C;
116+
} else {
117+
AC_CODE_TO_SEND = 0x88C0084;
118+
}
119+
120+
ac_send_code(AC_CODE_TO_SEND);
121+
122+
AC_AIR_ACLEAN = air_clean;
123+
}
124+
125+
void setup()
126+
{
127+
Serial.begin(38400);
128+
delay(1000);
129+
Wire.begin(7);
130+
Wire.onReceive(receiveEvent);
131+
132+
Serial.println(" - - - T E S T - - - ");
133+
134+
/* test
135+
ac_activate(25, 1);
136+
delay(5000);
137+
ac_activate(27, 2);
138+
delay(5000);
139+
140+
*/
141+
}
142+
143+
void loop()
144+
{
145+
146+
147+
ac_activate(25, 1);
148+
delay(5000);
149+
ac_activate(27, 0);
150+
delay(5000);
151+
152+
153+
if ( r != o_r) {
154+
155+
/*
156+
# a : mode or temp b : air_flow, temp, swing, clean
157+
# 18 ~ 30 : temp 0 ~ 2 : flow // on
158+
# 0 : off 0
159+
# 1 : on 0
160+
# 2 : air_swing 0 or 1
161+
# 3 : air_clean 0 or 1
162+
# 4 : air_flow 0 ~ 2 : flow
163+
# 5 : temp 18 ~ 30
164+
# + : temp + 1
165+
# - : temp - 1
166+
# m : change cooling to air clean, air clean to cooling
167+
*/
168+
Serial.print("a : ");
169+
Serial.print(a);
170+
Serial.print(" b : ");
171+
Serial.println(b);
172+
173+
switch (a) {
174+
case 0: // off
175+
ac_power_down();
176+
break;
177+
case 1: // on
178+
ac_activate(AC_TEMPERATURE, AC_FLOW);
179+
break;
180+
case 2:
181+
if ( b == 0 | b == 1 ) {
182+
ac_change_air_swing(b);
183+
}
184+
break;
185+
case 3: // 1 : clean on, power on
186+
if ( b == 0 | b == 1 ) {
187+
ac_air_clean(b);
188+
}
189+
break;
190+
case 4:
191+
if ( 0 <= b && b <= 2 ) {
192+
ac_activate(AC_TEMPERATURE, b);
193+
}
194+
break;
195+
case 5:
196+
if (18 <= b && b <= 30 ) {
197+
ac_activate(b, AC_FLOW);
198+
}
199+
break;
200+
case '+':
201+
if ( 18 <= AC_TEMPERATURE && AC_TEMPERATURE <= 29 ) {
202+
ac_activate((AC_TEMPERATURE + 1), AC_FLOW);
203+
}
204+
break;
205+
case '-':
206+
if ( 19 <= AC_TEMPERATURE && AC_TEMPERATURE <= 30 ) {
207+
ac_activate((AC_TEMPERATURE - 1), AC_FLOW);
208+
}
209+
break;
210+
case 'm':
211+
/*
212+
if ac is on, 1) turn off, 2) turn on ac_air_clean(1)
213+
if ac is off, 1) turn on, 2) turn off ac_air_clean(0)
214+
*/
215+
if ( AC_POWER_ON == 1 ) {
216+
ac_power_down();
217+
delay(100);
218+
ac_air_clean(1);
219+
} else {
220+
if ( AC_AIR_ACLEAN == 1) {
221+
ac_air_clean(0);
222+
delay(100);
223+
}
224+
ac_activate(AC_TEMPERATURE, AC_FLOW);
225+
}
226+
break;
227+
default:
228+
if ( 18 <= a && a <= 30 ) {
229+
if ( 0 <= b && b <= 2 ) {
230+
ac_activate(a, b);
231+
}
232+
}
233+
}
234+
235+
o_r = r ;
236+
}
237+
delay(100);
238+
}
239+
240+
241+
242+
void receiveEvent(int howMany)
243+
{
244+
a = Wire.read();
245+
b = Wire.read();
246+
r = !r ;
247+
}
248+
249+

examples/LGACSendDemo/LGACSendDemo.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
1) Sample raw code : https://gist.github.com/chaeplin/ab2a7ad1533c41260f0d
2+
2) send raw code : https://gist.github.com/chaeplin/7c800d3166463bb51be4
3+
4+
5+
=== *** ===
6+
- (1) : fixed
7+
- (2) : fixed
8+< F438 div class="diff-text-inner">- (3) : special(power, swing, air clean)
9+
- (4) : change air flow, temperature
10+
- (5) : temperature ( 15 + (5) = )
11+
- (6) : air flow
12+
- (7) : crc ( 3 + 4 + 5 + 6 ) & B00001111
13+
14+
=== *** ===
15+
16+
| status | (1)| (2)| (3)| (4)| (5)| (6)| (7)
17+
|----------------|----|----|----|----|----|----|----
18+
| on / 25 / mid |1000|1000|0000|0000|1010|0010|1100
19+
| on / 26 / mid |1000|1000|0000|0000|1011|0010|1101
20+
| on / 27 / mid |1000|1000|0000|0000|1100|0010|1110
21+
| on / 28 / mid |1000|1000|0000|0000|1101|0010|1111
22+
| on / 25 / high |1000|1000|0000|0000|1010|0100|1110
23+
| on / 26 / high |1000|1000|0000|0000|1011|0100|1111
24+
| on / 27 / high |1000|1000|0000|0000|1100|0100|0000
25+
| on / 28 / high |1000|1000|0000|0000|1101|0100|0001
26+
| 1 up |1000|1000|0000|1000|1101|0100|1001
27+
| Cool power |1000|1000|0001|0000|0000|1100|1101
28+
| energy saving |1000|1000|0001|0000|0000|0100|0101
29+
| power |1000|1000|0001|0000|0000|1000|1001
30+
| flow/up/down |1000|1000|0001|0011|0001|0100|1001
31+
| up/down off |1000|1000|0001|0011|0001|0101|1010
32+
| flow/left/right|1000|1000|0001|0011|0001|0110|1011
33+
| left/right off |1000|1000|0001|0011|0001|0111|1100
34+
| Air clean |1000|1000|1100|0000|0000|0000|1100
35+
| off |1000|1000|1100|0000|0000|0101|0001

ir_LG.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,29 @@ bool IRrecv::decodeLG (decode_results *results)
5252
}
5353
#endif
5454

55+
//+=============================================================================
56+
#if SEND_LG
57+
void IRsend::sendLG (unsigned long data, int nbits)
58+
{
59+
// Set IR carrier frequency
60+
enableIROut(38);
61+
62+
// Header
63+
mark(LG_HDR_MARK);
64+
space(LG_HDR_SPACE);
65+
mark(LG_BIT_MARK);
66+
67+
// Data
68+
for (unsigned long mask = 1UL << (nbits - 1); mask; mask >>= 1) {
69+
if (data & mask) {
70+
space(LG_ONE_SPACE);
71+
mark(LG_BIT_MARK);
72+
} else {
73+
space(LG_ZERO_SPACE);
74+
mark(LG_BIT_MARK);
75+
}
76+
}
77+
space(0); // Always end with the LED off
78+
}
79+
#endif
80+

0 commit comments

Comments
 (0)
0