/*
* SimpleSender.cpp
*
* Demonstrates sending IR codes in standard format with address and command
* An extended example for sending can be found as SendDemo.
*
* Copyright (C) 2020-2022 Armin Joachimsmeyer
* [email protected]
*
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
*
* MIT License
*/
#include <Arduino.h>
#define DISABLE_CODE_FOR_RECEIVER // Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used.
//#define SEND_PWM_BY_TIMER // Disable carrier PWM generation in software and use (restricted) hardware PWM.
//#define USE_NO_SEND_PWM // Use no carrier PWM, just simulate an active low receiver signal. Overrides SEND_PWM_BY_TIMER definition
#include <IRremote.hpp>
void setup() {
Serial1.begin(115200);
Serial1.println("Hello, world!");
// Just to know which program is running on my Arduino
Serial1.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
/*
* The IR library setup. That's all!
*/
// IrSender.begin(); // Start with IR_SEND_PIN as send pin and if NO_LED_FEEDBACK_CODE is NOT defined, enable feedback LED at default feedback LED pin
//IrSender.begin(DISABLE_LED_FEEDBACK); // Start with IR_SEND_PIN as send pin and disable feedback LED at default feedback LED pin
Serial1.print(F("Send IR signals at pin "));
IrSender.setSendPin(16);
}
/*
* Set up the data to be sent.
* For most protocols, the data is build up with a constant 8 (or 16 byte) address
* and a variable 8 bit command.
* There are exceptions like Sony and Denon, which have 5 bit address.
*/
uint8_t sAddress = 0x02;
uint8_t sCommand = 0x34;
uint8_t sRepeats = 10;
void loop() {
/*
* Print current send values
*/
Serial1.println();
Serial1.print(F("Send now: address=0x"));
Serial1.print(sAddress, HEX);
Serial1.print(F(" command=0x"));
Serial1.print(sCommand, HEX);
Serial1.print(F(" repeats="));
Serial1.print(sRepeats);
Serial1.println();
Serial1.println(F("Send NEC with 8 bit address"));
Serial1.flush();
// Receiver output for the first loop must be: Protocol=NEC Address=0x102 Command=0x34 Raw-Data=0xCB340102 (32 bits)
IrSender.sendNEC(sAddress, sCommand, sRepeats);
/*
* If you must send a raw value directly like e.g. 0xCB340102, you have to use sendNECRaw()
*/
// Serial.println(F("Send NECRaw 0xCB340102"));
// IrSender.sendNECRaw(0xCB340102, sRepeats);
/*
* Increment send values
* Also increment address just for demonstration, which normally makes no sense
*/
sAddress += 0x0101;
sCommand += 0x11;
sRepeats++;
// clip repeats at 4
if (sRepeats > 5) {
sRepeats = 4;
}
delay(10000); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal
}