Created
June 12, 2020 08:56
-
-
Save bengtmartensson/ef8f12e070e37bb1047ef88410fbd86f to your computer and use it in GitHub Desktop.
Lasko fan sketch, see https://github.com/z3t0/Arduino-IRremote/issues/692
This file contains 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
// 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 | |
// For problems, bugs, and suggestions, please open an issue at | |
// https://github.com/bengtmartensson/IrScrutinizer/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: first | |
// Protocol: f12_relaxed, Parameters: S=1 D=3 F=129 | |
const microseconds_t repeat_first[] PROGMEM = { 1266U, 422U, 1266U, 422U, 422U, 1266U, 1266U, 422U, 1266U, 422U, 422U, 1266U, 422U, 1266U, 422U, 1266U, 422U, 1266U, 422U, 1266U, 422U, 1266U, 1266U, 34182 }; | |
// Command #2: second | |
// Protocol: f12_relaxed, Parameters: S=1 D=3 F=65 | |
const microseconds_t repeat_second[] PROGMEM = { 1266U, 422U, 1266U, 422U, 422U, 1266U, 1266U, 422U, 1266U, 422U, 422U, 1266U, 422U, 1266U, 422U, 1266U, 422U, 1266U, 422U, 1266U, 1266U, 422U, 422U, 35026 }; | |
// Command #3: third | |
// Protocol: f12_relaxed, Parameters: S=1 D=3 F=9 | |
const microseconds_t repeat_third[] PROGMEM = { 1266U, 422U, 1266U, 422U, 422U, 1266U, 1266U, 422U, 1266U, 422U, 422U, 1266U, 422U, 1266U, 1266U, 422U, 422U, 1266U, 422U, 1266U, 422U, 1266U, 422U, 35026 }; | |
// Command #4: forth | |
// Protocol: f12_relaxed, Parameters: S=1 D=3 F=17 | |
const microseconds_t repeat_forth[] PROGMEM = { 1266U, 422U, 1266U, 422U, 422U, 1266U, 1266U, 422U, 1266U, 422U, 422U, 1266U, 422U, 1266U, 422U, 1266U, 1266U, 422U, 422U, 1266U, 422U, 1266U, 422U, 35026 }; | |
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 .. 4)")); | |
long commandno = Serial.parseInt(); | |
Serial.println(F("Enter number of times to send it")); | |
long times = Serial.parseInt(); | |
switch (commandno) { | |
case 1U: | |
sendRaw(NULL, 0U, repeat_first, 24U, 37900U, times); | |
break; | |
case 2U: | |
sendRaw(NULL, 0U, repeat_second, 24U, 37900U, times); | |
break; | |
case 3U: | |
sendRaw(NULL, 0U, repeat_third, 24U, 37900U, times); | |
break; | |
case 4U: | |
sendRaw(NULL, 0U, repeat_forth, 24U, 37900U, 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