Created
May 24, 2020 07:59
-
-
Save eudoxos/f2c1439adb56ac0b01f7dc523a6d8978 to your computer and use it in GitHub Desktop.
Comparing IR sending libraries for Arduino
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// send a single IR NEC-encoded frabe over IR using 3 different libs | |
// #define LIB_IRREMOTE | |
// #define LIB_IRLIB2 | |
#define LIB_IR4A | |
const byte IR_CMD=0xe0; | |
const byte IR_DEV = 0x00; | |
// frame structure: devId, 0xff-devId, cmd, 0xff-cmd | |
union Frame { uint32_t data; byte b[4]; }; | |
// little endian: bytes stored in reverse | |
Frame frame{.b = {0xff - IR_CMD, IR_CMD, 0xff - IR_DEV, IR_DEV}}; | |
#ifdef LIB_IRREMOTE | |
#include <IRremote.h> | |
IRsend irsend; | |
#elif defined(LIB_IRLIB2) | |
#include<IRLibSendBase.h> | |
#include<IRLib_P01_NEC.h> | |
IRsendNEC ir2sendNEC; | |
#elif defined(LIB_IR4A) | |
#include<Nec1Renderer.h> | |
#include<IrSenderPwm.h> | |
IrSignal* sig = Nec1Renderer::newIrSignal(IR_DEV, IR_CMD); | |
void operator delete(void* p, size_t) { free(p); } | |
#else | |
#error One of LIB_IRREMOTE, LIB_IRLIB2, LIB_IR4A must be defined. | |
#endif | |
void setup() | |
{ | |
pinMode(LED_BUILTIN, OUTPUT); | |
} | |
void loop() { | |
digitalWrite(LED_BUILTIN, HIGH); | |
#ifdef LIB_IRREMOTE | |
irsend.sendNEC(frame.data, 32); | |
#elif defined(LIB_IRLIB2) | |
ir2sendNEC.send(frame.data); | |
#elif defined(LIB_IR4A) | |
IrSenderPwm::getInstance(true)->sendIrSignal(*sig, 1); | |
#else | |
#error | |
#endif | |
delay(200); | |
digitalWrite(LED_BUILTIN, LOW); | |
delay(800); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment