Skip to content

Instantly share code, notes, and snippets.

@ytsuboi
Created January 8, 2013 14:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ytsuboi/4484110 to your computer and use it in GitHub Desktop.
Save ytsuboi/4484110 to your computer and use it in GitHub Desktop.
Arduinoを赤外線リモコンにするスケッチ。 とりあえず家電協とNECフォーマットに対応。たぶんSONYフォーマットにも対応させます。
/*
# 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[6] = {0xAA, 0x5A, 0x8F, 0x12, 0x16, 0xD1}; // AQUOS 0xAA 0x5A 0x8F 0x12 0x16 0xD1
// unsigned char data[4] = {0x40, 0xBF, 0x12, 0xED}; // REGZA 0x40 0xBF 0x12 0xED
void loop() {
sendIrAEHA(); // AQUOS
// sendIrNEC(); // REGZA
while(1);
}
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 ); // 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
}
}
@sgk
Copy link

sgk commented Jan 8, 2013

スペースの空け方とか、改行とかがイヤ・・・

@ytsuboi
Copy link
Author

ytsuboi commented Jan 8, 2013

てへぺろ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment