Go Down

Topic: Solved: LG air conditioning codes (Read 21 times) previous topic - next topic



argonauta1

dear Adis,

may post code to clone the LG remote control, and the code to send commands acquired??

PS: I am using the examples of Ken Shirriff (IRrecvDemo.ino or IRrecvDump.ino) I get a 16-bit code (the original code is 24-bit.) These are the first 16 bits of the command.

thank you very much :-)
(sorry for my bad english)

Alessandro

adis

Hi,

Below is the test program and a library I wrote in january.
I did my best to make it as clear as possible.

Regards,
Adi

Code: [Select]

#include <LG.h>
#include <IRremote.h>

// the LG code generator object

// the IR emitter object
IRsend irsend;

void setup()
{
Serial.begin(9600);
Serial.println("Start");


// wait 5 seconds
//delay(5000);
//LG LG(mode_heating,fan_4,30,state_on);
//LG LG(mode_heating,fan_4,30,state_off);
LG LG(mode_cooling,fan_1,18 ,state_on);


LG.debug();
// change the state
//LG.setState(STATE_off);
// send the code

irsend.sendRaw(LG.codes,LG_buffer_size,38);
//
Serial.println("End");



// wait 10 seconds
//delay(10000);

// change the state
//LG.setState(STATE_on);
// send the code
//irsend.sendRaw(LG.codes,LG_buffer_size,38);
}

void loop() {}


LG.h
Code: [Select]

#ifndef LG_h
#define LG_h
#include <WProgram.h>

#define first_byte 136 //b10001000

#define state_on 0
#define state_off 24 //b11000
#define state_change_mode 1

#define mode_heating 4 //b100
#define mode_auto 3 //b011
#define mode_dehuidification 1 //b001
#define mode_cooling 0
#define mode_none 0

#define temperature_offset 15

#define fan_1 1
#define fan_2 0
#define fan_3 2
#define fan_4 4 //b100
#define fan_none 5 //b101

#define first_high 8271
#define first_low 4298
#define zero_and_one_high 439
#define zero_low 647
#define one_low 1709

#define LG_buffer_size 59

class LG
{
public:
// fields
unsigned int codes[LG_buffer_size];
// methods
// setter
LG(int _mode,
int _fan,
int _temperature,
int _state);
// getter
// debugging
void debug();
private:
// fields
byte crc;
// methods
void FillBuffer(byte _pos, byte _bit, byte _value);
};

#endif;

LG.cpp
Code: [Select]

#include "LG.h"
LG::LG(int _mode,
int _fan,
int _temperature,
int _state)
{
// set sync
codes[0] = first_high;
codes[1] = first_low;
crc = 0;
FillBuffer(0,8,first_byte);
FillBuffer(8,5,_state);
if(_state==state_off)
FillBuffer(13,3,mode_none);
else
FillBuffer(13,3,_mode);
if(_state==state_off)
FillBuffer(16,4,0);
else
FillBuffer(16,4,(byte)_temperature-temperature_offset);
FillBuffer(20,1,0); //jet
if(_state==state_off)
FillBuffer(21,3,fan_none);
else
FillBuffer(21,3,_fan);
FillBuffer(24,4,crc);
codes[LG_buffer_size-1] = zero_and_one_high;
}

void LG::FillBuffer(byte _pos, byte _bits, byte _value){
for (int i=_bits;i>0;i--){
codes[2+2*(_pos+_bits-i)] = zero_and_one_high;
codes[2+2*(_pos+_bits-i)+1] = (bitRead(_value,i-1)==1?one_low:zero_low);
if(bitRead(_value,i-1)==1){
byte bitset = 0;
bitSet(bitset,(128+i-_pos-_bits-1)%4);
crc = crc + bitset;
}
}
}
void LG::debug()
{
for(byte i=0;i<LG_buffer_size;i++){
Serial.print(codes[i],DEC);
Serial.print(",");
}
}

argonauta1

Another HELP!!??? XD   :D

I use Arduino 1.0.1
in the verification phase of the first code posted by Adis:

[ERROR]
Programmi\arduino-1.0.1\libraries\LG/LG.h:49: error: 'byte' does not name a type
Programmi\arduino-1.0.1\libraries\LG/LG.h:51: error: 'byte' does not name a type
Programmi\arduino-1.0.1\libraries\LG/LG.h:51: error: 'byte' does not name a type
Programmi\arduino-1.0.1\libraries\LG/LG.h:51: error: 'byte' does not name a type

[Possible solution] in 'LG.h' I changed the code to "unsigned char"................ but appears a new error:

sketch_LG_ino.cpp.o: In function `setup':
C:\Users\ALESSA~1\AppData\Local\Temp\build6352010931496577367.tmp/sketch_LG_ino.cpp:22: undefined reference to `LG::LG(int, int, int, int)'
C:\Users\ALESSA~1\AppData\Local\Temp\build6352010931496577367.tmp/sketch_LG_ino.cpp:25: undefined reference to `LG::debug()'

Go Up