2015-08-25 04:25:22 +08:00
/*
2021-03-09 04:38:06 +08:00
* SendRawDemo . cpp - demonstrates sending IR codes with sendRaw
2015-08-25 04:25:22 +08:00
*
* This example shows how to send a RAW signal using the IRremote library .
* The example signal is actually a 32 bit NEC signal .
2020-07-04 08:00:50 +08:00
* Remote Control button : LGTV Power On / Off .
2015-08-25 04:25:22 +08:00
* Hex Value : 0x20DF10EF , 32 bits
2020-07-04 08:00:50 +08:00
*
2022-05-30 05:01:38 +08:00
* If it is a supported protocol , it is more efficient to use the protocol send function
* ( here sendNEC ) to send the signal .
2020-07-04 08:00:50 +08:00
*
2021-03-06 08:21:46 +08:00
* This file is part of Arduino - IRremote https : //github.com/Arduino-IRremote/Arduino-IRremote.
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MIT License
*
2022-01-29 17:44:14 +08:00
* Copyright ( c ) 2020 - 2022 Armin Joachimsmeyer
2021-03-06 08:21:46 +08:00
*
* 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>
2024-02-29 09:05:55 +08:00
# 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
2022-11-14 22:00:43 +08:00
2022-08-18 01:29:01 +08:00
//#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 USE_OPEN_DRAIN_OUTPUT_FOR_SEND_PIN // Use or simulate open drain output mode at send pin. Attention, active state of open drain is LOW, so connect the send LED between positive supply and send pin!
2022-08-28 02:22:58 +08:00
# include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
2021-10-18 01:29:20 +08:00
# include <IRremote.hpp>
2015-08-25 04:25:22 +08:00
2020-07-04 08:00:50 +08:00
void setup ( ) {
pinMode ( LED_BUILTIN , OUTPUT ) ;
Serial . begin ( 115200 ) ;
2022-04-05 10:47:32 +08:00
# if defined(__AVR_ATmega32U4__) || defined(SERIAL_PORT_USBVIRTUAL) || defined(SERIAL_USB) /*stm32duino*/ || defined(USBCON) /*STM32_stm32*/ || defined(SERIALUSB_PID) || defined(ARDUINO_attiny3217)
2021-04-08 07:51:03 +08:00
delay ( 4000 ) ; // To be able to connect Serial monitor after reset or power up and before first print out. Do not wait for an attached Serial Monitor!
2020-07-04 08:00:50 +08:00
# endif
// Just to know which program is running on my Arduino
2021-01-02 22:24:51 +08:00
Serial . println ( F ( " START " __FILE__ " from " __DATE__ " \r \n Using library version " VERSION_IRREMOTE ) ) ;
2023-02-20 10:22:15 +08:00
Serial . println ( F ( " Send IR signals at pin " STR ( IR_SEND_PIN ) ) ) ;
2021-03-09 04:38:06 +08:00
2024-02-27 16:55:39 +08:00
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
2015-08-25 04:25:22 +08:00
}
2020-11-05 00:10:32 +08:00
/*
* NEC address = 0xFB0C , command = 0x18
*
* This is data in byte format .
2021-01-02 09:05:20 +08:00
* 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 ,
2021-01-15 22:57:40 +08:00
* you better use the timing generation functions e . g . sendNEC ( ) directly .
2020-11-05 00:10:32 +08:00
*/
2022-12-24 20:13:22 +08:00
const uint8_t rawDataP [ ]
# if defined(__AVR__)
PROGMEM
# endif
2021-09-07 05:09:48 +08:00
= { 180 , 90 /*Start bit*/ , 11 , 11 , 11 , 11 , 11 , 34 , 11 , 34 /*0011 0xC of 16 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 ,
2020-11-05 00:10:32 +08:00
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*/ } ;
2015-08-25 04:25:22 +08:00
void loop ( ) {
2021-01-02 13:20:07 +08:00
# if !(defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__))
2020-07-04 08:00:50 +08:00
/*
2020-11-05 00:10:32 +08:00
* Send hand crafted data from RAM
* The values are NOT multiple of 50 , but are taken from the NEC timing definitions
2020-07-04 08:00:50 +08:00
*/
2021-09-07 05:09:48 +08:00
Serial . println ( F ( " Send NEC 16 bit address=0xFB04 and command 0x08 with exact timing (16 bit array format) " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-01-14 20:32:53 +08:00
2022-05-30 05:01:38 +08:00
const uint16_t rawData [ ] = { 9000 , 4500 /*Start bit*/ , 560 , 560 , 560 , 560 , 560 , 1690 , 560 ,
2021-09-07 05:09:48 +08:00
560 /*0010 0x4 of 16 bit address LSB first*/ , 560 , 560 , 560 , 560 , 560 , 560 , 560 , 560 /*0000*/ , 560 , 1690 , 560 , 1690 , 560 ,
560 , 560 , 1690 /*1101 0xB*/ , 560 , 1690 , 560 , 1690 , 560 , 1690 , 560 , 1690 /*1111*/ , 560 , 560 , 560 , 560 , 560 , 560 , 560 ,
1690 /*0001 0x08 of command LSB first*/ , 560 , 560 , 560 , 560 , 560 , 560 , 560 , 560 /*0000 0x00*/ , 560 , 1690 , 560 , 1690 , 560 ,
1690 , 560 , 560 /*1110 Inverted 8 of command*/ , 560 , 1690 , 560 , 1690 , 560 , 1690 , 560 , 1690 /*1111 inverted 0 of command*/ ,
560 /*stop bit*/ } ; // Using exact NEC timing
2022-05-30 05:01:38 +08:00
IrSender . sendRaw ( rawData , sizeof ( rawData ) / sizeof ( rawData [ 0 ] ) , NEC_KHZ ) ; // Note the approach used to automatically calculate the size of the array.
2020-07-04 08:00:50 +08:00
2021-01-24 19:46:58 +08:00
delay ( 1000 ) ; // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal
2021-01-02 13:20:07 +08:00
# endif
2020-11-05 00:10:32 +08:00
2020-07-04 08:00:50 +08:00
/*
2020-11-05 00:10:32 +08:00
* Send byte data direct from FLASH
* Note the approach used to automatically calculate the size of the array .
2020-07-04 08:00:50 +08:00
*/
2021-09-07 05:09:48 +08:00
Serial . println ( F ( " Send NEC 16 bit address 0xFB0C and data 0x18 with (50 us) tick resolution timing (8 bit array format) " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2022-05-30 05:01:38 +08:00
IrSender . sendRaw_P ( rawDataP , sizeof ( rawDataP ) / sizeof ( rawDataP [ 0 ] ) , NEC_KHZ ) ;
2020-11-05 00:10:32 +08:00
2021-01-24 19:46:58 +08:00
delay ( 1000 ) ; // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal
2020-11-05 00:10:32 +08:00
2020-12-31 11:51:54 +08:00
Serial . println ( F ( " Send NEC 16 bit address 0x0102, 8 bit data 0x34 with generated timing " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2022-08-31 20:07:41 +08:00
IrSender . sendNEC ( 0x0102 , 0x34 , 0 ) ;
2015-08-25 04:25:22 +08:00
2020-11-05 00:10:32 +08:00
delay ( 3000 ) ;
2015-08-25 04:25:22 +08:00
}