#include <Arduino.h>
/*
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>
#if !defined(ARDUINO_ESP32C3_DEV) // This is due to a bug in RISC-V compiler, which requires unused function sections :-(.
#define DISABLE_CODE_FOR_RECEIVER // Disables static receiver code like receive timer ISR handler and static IRReceiver and irparams data. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not required.
#endif
//#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
/*
This include defines the actual pin number for pins like IR_RECEIVE_PIN, IR_SEND_PIN for many different boards and architectures
*/
#include "PinDefinitionsAndMore.h"
#include <IRremote.hpp> // include the library
int led_pin = 5;
int led_state = 0;
int button_pin = 2;
int change = 0;
void change_led_state_and_send() {
change = 1;
}
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(115200);
while (!Serial); // Wait for Serial to become available. Is optimized away for some cores.
// Just to know which program is running on my Arduino
Serial.println(F("START " __FILE__ " from " __DATE__ "\r\nUsing library version " VERSION_IRREMOTE));
Serial.print(F("Send IR signals at pin "));
Serial.println(IR_SEND_PIN);
/*
The IR library setup. That's all!
*/
IrSender.begin(); // Start with IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin and enable feedback LED at default feedback LED pin
disableLEDFeedback(); // Disable feedback LED at default feedback LED pin
pinMode(led_pin, OUTPUT);
pinMode(button_pin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(button_pin), change_led_state_and_send, CHANGE);
}
void loop() {
if (change) {
led_state = !led_state;
Serial.println();
Serial.print(F("Send now: address=0x00, command=0x"));
Serial.print(led_state, HEX);
Serial.print(F(", repeats="));
Serial.print(0);
Serial.println();
IrSender.sendNEC(0x00, led_state, 0x00);
delay(100);//anti bounce deklal
change = 0;
}
digitalWrite(led_pin, led_state);
delay(1000); // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal
}