elbear_arduino_bsp/libraries/IRremote/examples/SendRawDemo/SendRawDemo.ino
KlassenTS 1c8e06634c v0.5.0
- добавлена поддержка платы ELBEAR ACE-NANO;
- добавлена поддержка плат ELSOMIK OEM и SE;
- добавлена возможность работы в режиме отладки для всех плат, входящих в состав пакета. Доступно для версии ArduinoIDE 2 и выше;
- добавлена поддержка библиотеки FreeRTOS;
- добавлена поддержка библиотеки IRremote;
- добавлена поддержка библиотеки OneWire;
- добавлена поддержка аппаратного I2C0 для плат START-MIK32 и ELSOMIK. Для работы с ним доступен экземпляр класса Wire1;
- добавлена поддержка аппаратного SPI0 для всех плат, входящих в пакет. Для работы с ним доступен экземпляр класса SPI1;
- увеличено быстродействие функций digitalWrite, digitalRead;
- исправлены известные ошибки.
Co-authored-by: KlassenTS <klassen@elron.tech>
Co-committed-by: KlassenTS <klassen@elron.tech>
2025-04-28 07:06:08 +03:00

125 lines
5.9 KiB
C++

/*
* SendRawDemo.cpp - demonstrates sending IR codes with sendRaw
*
* This example shows how to send a RAW signal using the IRremote library.
* The example signal is actually a 32 bit NEC signal.
* Protocol=NEC Address=0x4 Command=0x18 Raw-Data=0xE718FB04 32 bits LSB first
*
* If it is a supported protocol, it is more efficient to use the protocol send function
* (here sendNEC) to send the signal.
*
* This file is part of Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
*
************************************************************************************
* MIT License
*
* Copyright (c) 2020-2024 Armin Joachimsmeyer
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is furnished
* to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
* PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
* CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*
************************************************************************************
*/
#include <Arduino.h>
//#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
//#define NO_LED_FEEDBACK_CODE // Saves 566 bytes program memory
#define IR_SEND_PIN 3 // P0_0
/*
* Helper macro for getting a macro definition as string
*/
#if !defined(STR_HELPER)
#define STR_HELPER(x) #x
#define STR(x) STR_HELPER(x)
#endif
#include <IRremote.hpp>
void setup() {
pinMode(LED_BUILTIN, OUTPUT);
Serial.begin(9600);
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.println(F("Send IR signals at pin " STR(IR_SEND_PIN)));
IrSender.begin(); // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin
}
/*
* NEC address=0x04 (0xFB04), command=0x18 (0xE718)
*
* This is the raw data array in byte format.
* The uint8_t/byte elements contain the number of ticks in 50 us.
* The uint16_t format contains the (number of ticks * 50) if generated by IRremote,
* so the uint16_t format has exact the same resolution but requires double space.
* With the uint16_t format, you are able to modify the timings to meet the standards,
* e.g. use 560 (instead of 11 * 50) for NEC or use 432 for Panasonic. But in this cases,
* you better use the timing generation functions e.g. sendNEC() directly.
*/
const uint8_t rawDataP[] =
{ 180, 90 /*Start bit*/, 11, 11, 11, 11, 11, 34, 11, 11/*0010 0x4 of 8 bit address LSB first*/, 11, 11, 11, 11, 11, 11, 11,
11/*0000*/, 11, 34, 11, 34, 11, 11, 11, 34/*1101 0xB*/, 11, 34, 11, 34, 11, 34, 11, 34/*1111*/, 11, 11, 11, 11, 11, 11, 11,
34/*0001 0x08 of command LSB first*/, 11, 34, 11, 11, 11, 11, 11, 11/*1000 0x01*/, 11, 34, 11, 34, 11, 34, 11,
11/*1110 Inverted 8 of command*/, 11, 11, 11, 34, 11, 34, 11, 34/*0111 inverted 1 of command*/, 11 /*stop bit*/};
/*
* The same frame as above. Values are NOT multiple of 50, but are taken from the NEC timing definitions
*/
const uint16_t rawData[] = { 9000, 4500/*Start bit*/, 560, 560, 560, 560, 560, 1690, 560,
560/*0010 0x4 of 8 bit address LSB first*/, 560, 560, 560, 560, 560, 560, 560, 560/*0000*/, 560, 1690, 560, 1690, 560, 560,
560, 1690/*1101 0xB - inverted 0x04*/, 560, 1690, 560, 1690, 560, 1690, 560, 1690/*1111 - inverted 0*/, 560, 560, 560, 560,
560, 560, 560, 1690/*0001 0x08 of command LSB first*/, 560, 1690, 560, 560, 560, 560, 560, 560/*1000 0x01*/, 560, 1690, 560,
1690, 560, 1690, 560, 560/*1110 Inverted 8 of command*/, 560, 560, 560, 1690, 560, 1690, 560,
1690/*1111 inverted 0 of command*/, 560 /*stop bit*/}; // Using exact NEC timing
void loop() {
/*
* Send hand crafted data from RAM
*/
Serial.println(F("Send NEC 8 bit address=0x04 (0xFB04) and command 0x18 (0xE718) with exact timing (16 bit array format)"));
Serial.flush();
IrSender.sendRaw(rawData, sizeof(rawData) / sizeof(rawData[0]), NEC_KHZ); // Note the approach used to automatically calculate the size of the array.
delay(1000); // delay must be greater than 8 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal
/*
* Send byte data direct from FLASH
* Note the approach used to automatically calculate the size of the array.
*/
Serial.println(F("Send NEC 8 bit address 0x04 and command 0x18 with (50 us) tick resolution timing (8 bit array format) "));
Serial.flush();
IrSender.sendRaw_P(rawDataP, sizeof(rawDataP) / sizeof(rawDataP[0]), NEC_KHZ);
delay(1000); // delay must be greater than 8 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal
/*
* Send the same frame using NEC encoder
*/
Serial.println(F("Send NEC 16 bit address 0x04, 8 bit command 0x18 with NEC encoder"));
Serial.flush();
IrSender.sendNEC(0x04, 0x18, 0);
delay(3000);
}