Skip to content

Instantly share code, notes, and snippets.

@sgk
Forked from ytsuboi/ir_send.ino
Last active December 11, 2015 10:19
Show Gist options
  • Save sgk/4586230 to your computer and use it in GitHub Desktop.
Save sgk/4586230 to your computer and use it in GitHub Desktop.
/*
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# Version 2, December 2004
#
# Copyright (C) 2013 Yoshihiro TSUBOI <ytsuboi-at-gmail.com>
#
# Everyone is permitted to copy and distribute verbatim or modified
# copies of this license document, and changing it is allowed as long
# as the name is changed.
#
# DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
# TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
#
# 0. You just DO WHAT THE FUCK YOU WANT TO.
Reffered: http://elm-chan.org/docs/ir_format.html
Reffered: http://hello-world.blog.so-net.ne.jp/archive/20110512
*/
#define IR_LED 7
void setup() {
pinMode(IR_LED, OUTPUT);
}
unsigned char data[] = {
// AQUOS 0xAA 0x5A 0x8F 0x12 0x16 0xD1
0xAA, 0x5A, 0x8F, 0x12, 0x16, 0xD1
#if 0
// REGZA 0x40 0xBF 0x12 0xED
0x40, 0xBF, 0x12, 0xED
#endif
};
void loop() {
sendIrAEHA(); // AQUOS
// sendIrNEC(); // REGZA
while (1) {
// do nothing
}
}
void sendIrAEHA() {
// T=425us
const int dataCount = sizeof (data) / sizeof (data[0]);
irPulse(3400, 1700); // Leader
for (int i = 0; i < dataCount; ++i) {
for (int j = 0; j < 8; ++j)
irPulse(425, (data[i] >> j) % 2 ? 1275 : 425); // Data
}
irPulse(425, 68000); // wait
irPulse(3400, 1700); // Repeat
for (int i = 0; i < dataCount; ++i) {
for (int j = 0; j < 8; ++j)
irPulse(425, (data[i] >> j) % 2 ? 1275 : 425); // Data
}
irPulse(425, 0); // Trailer
}
void sendIrNEC() {
// T=562us
const int dataCount = sizeof (data) / sizeof (data[0]);
irPulse(9000, 4500);i // Leader
for (int i = 0; i < dataCount; ++i) {
for(int j = 0; j < 8; ++j)
irPulse(562, (data[i] >> j) % 2 ? 1687 : 562); // Data
}
irPulse(562, 40000); // Trailer
}
void irPulse(unsigned long lenH, unsigned long lenL) {
unsigned long irExp = micros() + lenH;
while (irExp > micros()) { // Output pulse for lenH usec
digitalWrite(IR_LED, HIGH);
delayMicroseconds(5);
digitalWrite(IR_LED, LOW);
delayMicroseconds(9);
}
if (lenL > 16000) { // To avoid Arduino's delayMicroseconds limitation
delay(lenL / 1000);
} else {
delayMicroseconds(lenL); // for LenL usec
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment