Skip to content

Instantly share code, notes, and snippets.

@Tarlin
Created March 25, 2015 20:32
Show Gist options
  • Save Tarlin/2643f5b7c8c17edf185f to your computer and use it in GitHub Desktop.
Save Tarlin/2643f5b7c8c17edf185f to your computer and use it in GitHub Desktop.
#include <IRremote.h>
IRsend irsend;
void setup()
{
Serial.begin(9600);
}
// Sends ir byte codes in LG documentation to control
// LG devices. LG codes use the NEC protocol.
// The bits are reversed from the default NEC protocol
// here in each byte. Do not use with received codes
// from this library.
// The NEC code is 4 bytes, with the following bytes:
// DeviceID (always 0x04 for LG, reversed to 0x20 here)
// Compliment of DeviceID (always 0xDF here)
// IR Command Code
// Compliment of IR Command Code
void sendLGManualCode(unsigned char code) {
unsigned long NECCode = 0x20DF0000;
unsigned char CodeByte = 0x00;
for (int i = 0; i < 8; i++) {
if (code & 0x80) {
CodeByte |= (0x01 << i);
}
code <<= 1;
}
NECCode |= (CodeByte << 8l & 0xFF00) | (~CodeByte & 0xFF);
Serial.print(NECCode, HEX);
irsend.sendNEC(NECCode, 32);
}
void loop() {
if (Serial.available() > 0) {
unsigned char NewCode = 0x00;
int IncomingByte = Serial.read();
if (IncomingByte == 'A')
{
Serial.print("\n\rSending Vol+: ");
NewCode = 0x02;
}
if (IncomingByte == 'B')
{
Serial.print("\n\rSending Vol-: ");
NewCode = 0x03;
}
if (IncomingByte == 'C')
{
Serial.print("\n\rSending Input: ");
NewCode = 0x0B;
}
if (IncomingByte == 'D')
{
Serial.print("\n\rSending Mute: ");
NewCode = 0x09;
}
if (IncomingByte == 'E')
{
Serial.print("\n\rSending Power: ");
NewCode = 0x08;
}
if (NewCode != 0x00)
{
sendLGManualCode(NewCode);
}
}
delay(50);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment