Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
// This Arduino sketch was automatically generated by IrScrutinizer.
// It supports:
//
// * IRremote https://github.com/z3t0/Arduino-IRremote
// http://z3t0.github.io/Arduino-IRremote/
// * IRLib https://github.com/cyborg5/IRLib
// * Infrared4Arduino https://github.com/bengtmartensson/Infrared4Arduino,
// http://www.harctoolbox.org/Infrared4Arduino.html (planned)
// For problems, bugs, and suggestions, please open an issue at
// https://github.com/bengtmartensson/harctoolboxbundle/issues
// This file contains C identifiers which have been translated from command names.
// Define exactly one of these
// #define IRREMOTE
// #define IRLIB
#define INFRARED4ARDUINO
/////////////////////////////////////////////////////
// Sanity check
#if defined(IRREMOTE) & ( defined(IRLIB) | defined(INFRARED4ARDUINO) )
#error Must define only one of IRREMOTE, IRLIB, or INFRARED4ARDUINO
#endif
#if defined(IRLIB) & ( defined(IRREMOTE) | defined(INFRARED4ARDUINO) )
#error Must define only one of IRREMOTE, IRLIB, or INFRARED4ARDUINO
#endif
#if defined(INFRARED4ARDUINO) & ( defined(IRLIB) | defined(IRREMOTE) )
#error Must define only one of IRREMOTE, IRLIB, or INFRARED4ARDUINO
#endif
#ifdef IRREMOTE
#include <IRremote.h>
#elif defined(IRLIB)
#include <IRLib.h>
#define sendRaw send
#elif defined(INFRARED4ARDUINO)
#include <IrSenderPwm.h>
#else
#error Must defined one of IRREMOTE, IRLIB, or INFRARED4ARDUINO
#endif
#if defined(IRREMOTE) | defined(IRLIB)
typedef uint16_t microseconds_t; // Change if desired
typedef uint16_t frequency_t; // Change if desired
static inline unsigned hz2khz(frequency_t f) { return f/1000U; }
#endif
// Constants
static const long BAUD = 115200UL; // Change if desired
// Global variables
#ifdef IRREMOTE
IRsend irsend;
#elif defined(IRLIB)
IRsendRaw irsend;
#else
IrSender *irsend = IrSenderPwm::getInstance(true);
#endif
// Command #1: cmd_1
// Protocol: g.i.cable, Parameters: D=0 F=1
const microseconds_t intro_cmd_1[] PROGMEM = { 8820U, 4410U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 4410U, 490U, 4410U, 490U, 4410U, 490U, 41160 };
const microseconds_t repeat_cmd_1[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
// Command #2: cmd_2
// Protocol: g.i.cable, Parameters: D=0 F=2
const microseconds_t intro_cmd_2[] PROGMEM = { 8820U, 4410U, 490U, 2205U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 4410U, 490U, 4410U, 490U, 41160 };
const microseconds_t repeat_cmd_2[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
// Command #3: cmd_3
// Protocol: g.i.cable, Parameters: D=0 F=3
const microseconds_t intro_cmd_3[] PROGMEM = { 8820U, 4410U, 490U, 4410U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 2205U, 490U, 4410U, 490U, 4410U, 490U, 41160 };
const microseconds_t repeat_cmd_3[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
// Command #4: cmd_4
// Protocol: g.i.cable, Parameters: D=0 F=4
const microseconds_t intro_cmd_4[] PROGMEM = { 8820U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 4410U, 490U, 41160 };
const microseconds_t repeat_cmd_4[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
// Command #5: cmd_5
// Protocol: g.i.cable, Parameters: D=0 F=5
const microseconds_t intro_cmd_5[] PROGMEM = { 8820U, 4410U, 490U, 4410U, 490U, 2205U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 4410U, 490U, 2205U, 490U, 4410U, 490U, 41160 };
const microseconds_t repeat_cmd_5[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
// Command #6: cmd_6
// Protocol: g.i.cable, Parameters: D=0 F=6
const microseconds_t intro_cmd_6[] PROGMEM = { 8820U, 4410U, 490U, 2205U, 490U, 4410U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 2205U, 490U, 4410U, 490U, 41160 };
const microseconds_t repeat_cmd_6[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
// Command #7: cmd_7
// Protocol: g.i.cable, Parameters: D=0 F=7
const microseconds_t intro_cmd_7[] PROGMEM = { 8820U, 4410U, 490U, 4410U, 490U, 4410U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 41160 };
const microseconds_t repeat_cmd_7[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
// Command #8: cmd_8
// Protocol: g.i.cable, Parameters: D=0 F=8
const microseconds_t intro_cmd_8[] PROGMEM = { 8820U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 41160 };
const microseconds_t repeat_cmd_8[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
// Command #9: cmd_9
// Protocol: g.i.cable, Parameters: D=0 F=9
const microseconds_t intro_cmd_9[] PROGMEM = { 8820U, 4410U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 4410U, 490U, 4410U, 490U, 4410U, 490U, 2205U, 490U, 41160 };
const microseconds_t repeat_cmd_9[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
// Command #10: cmd_0
// Protocol: g.i.cable, Parameters: D=0 F=0
const microseconds_t intro_cmd_0[] PROGMEM = { 8820U, 4410U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 2205U, 490U, 41160 };
const microseconds_t repeat_cmd_0[] PROGMEM = { 8820U, 2205U, 490U, 65535U };
static void sendRaw(const microseconds_t intro_P[], size_t lengthIntro, const microseconds_t repeat_P[],
size_t lengthRepeat, frequency_t frequency, unsigned times) {
microseconds_t intro[lengthIntro];
microseconds_t repeat[lengthRepeat];
memcpy_PF(intro, (uint_farptr_t) intro_P, sizeof(microseconds_t) * lengthIntro);
memcpy_PF(repeat, (uint_farptr_t) repeat_P, sizeof(microseconds_t) * lengthRepeat);
#if defined(IRREMOTE) | defined(IRLIB)
if (lengthIntro > 0U)
irsend.sendRaw(intro, lengthIntro, hz2khz(frequency));
if (lengthRepeat > 0U)
for (unsigned i = 0U; i < times - (lengthIntro > 0U); i++)
irsend.sendRaw(repeat, lengthRepeat, hz2khz(frequency));
#else // INFRARED4ARDUINO
IrSignal irSignal(intro, lengthIntro, repeat, lengthRepeat, NULL, 0U, frequency);
irsend->sendIrSignal(irSignal, times);
#endif
}
void setup() {
Serial.begin(BAUD);
Serial.setTimeout(60000UL);
}
// A pretty silly main loop; just intended as an example.
void loop() {
Serial.println(F("Enter number of signal to send (1 .. 10)"));
long commandno = Serial.parseInt();
Serial.println(F("Enter number of times to send it"));
long times = Serial.parseInt();
switch (commandno) {
case 1U:
sendRaw(intro_cmd_1, 36U, repeat_cmd_1, 4U, 38700U, times);
break;
case 2U:
sendRaw(intro_cmd_2, 36U, repeat_cmd_2, 4U, 38700U, times);
break;
case 3U:
sendRaw(intro_cmd_3, 36U, repeat_cmd_3, 4U, 38700U, times);
break;
case 4U:
sendRaw(intro_cmd_4, 36U, repeat_cmd_4, 4U, 38700U, times);
break;
case 5U:
sendRaw(intro_cmd_5, 36U, repeat_cmd_5, 4U, 38700U, times);
break;
case 6U:
sendRaw(intro_cmd_6, 36U, repeat_cmd_6, 4U, 38700U, times);
break;
case 7U:
sendRaw(intro_cmd_7, 36U, repeat_cmd_7, 4U, 38700U, times);
break;
case 8U:
sendRaw(intro_cmd_8, 36U, repeat_cmd_8, 4U, 38700U, times);
break;
case 9U:
sendRaw(intro_cmd_9, 36U, repeat_cmd_9, 4U, 38700U, times);
break;
case 10U:
sendRaw(intro_cmd_0, 36U, repeat_cmd_0, 4U, 38700U, times);
break;
default:
Serial.println(F("Invalid number entered, try again"));
break;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.