2010-01-23 14:08:26 +08:00
/*
2021-03-09 04:38:06 +08:00
* SendDemo . cpp
2020-12-31 11:51:54 +08:00
*
2021-01-24 19:46:58 +08:00
* Demonstrates sending IR codes in standard format with address and command
2020-12-31 11:51:54 +08:00
*
2021-03-06 08:21:46 +08:00
* This file is part of Arduino - IRremote https : //github.com/Arduino-IRremote/Arduino-IRremote.
2020-12-31 11:51:54 +08:00
*
2021-03-06 08:21:46 +08:00
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* MIT License
2020-12-31 11:51:54 +08:00
*
2023-02-24 09:40:21 +08:00
* Copyright ( c ) 2020 - 2023 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 .
*
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
2021-04-19 20:06:29 +08:00
2021-03-06 08:21:46 +08:00
# include <Arduino.h>
2022-11-22 19:28:10 +08:00
# include "PinDefinitionsAndMore.h" // Define macros for input and output pin etc.
2023-02-24 09:40:21 +08:00
# define DISABLE_CODE_FOR_RECEIVER // Disables restarting receiver after each send. Saves 450 bytes program memory and 269 bytes RAM if receiving functions are not used.
2022-11-14 22:00:43 +08:00
2022-08-18 01:29:01 +08:00
//#define EXCLUDE_EXOTIC_PROTOCOLS // Saves around 240 bytes program memory if IrSender.write is 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
//#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!
2021-03-02 22:25:39 +08:00
2021-10-18 01:29:20 +08:00
# include <IRremote.hpp>
2021-03-02 22:25:39 +08:00
2021-03-09 04:38:06 +08:00
# define DELAY_AFTER_SEND 2000
# define DELAY_AFTER_LOOP 5000
2020-06-01 09:47:09 +08:00
void setup ( ) {
2020-07-02 02:46:29 +08:00
Serial . begin ( 115200 ) ;
2022-01-27 01:36:50 +08:00
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-06-01 09:47:09 +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 ) ) ;
2021-03-09 04:38:06 +08:00
2022-01-27 01:36:50 +08:00
# if defined(IR_SEND_PIN)
IrSender . begin ( ) ; // Start with IR_SEND_PIN as send pin and enable feedback LED at default feedback LED pin
2022-11-22 19:28:10 +08:00
# if defined(IR_SEND_PIN_STRING)
2022-12-14 01:40:50 +08:00
Serial . println ( F ( " Send IR signals at pin " IR_SEND_PIN_STRING ) ) ;
2022-11-22 19:28:10 +08:00
# else
2022-11-14 22:00:43 +08:00
Serial . println ( F ( " Send IR signals at pin " STR ( IR_SEND_PIN ) ) ) ;
2022-11-22 19:28:10 +08:00
# endif
2021-11-03 13:57:27 +08:00
# else
2022-10-19 16:50:44 +08:00
IrSender . begin ( 3 , ENABLE_LED_FEEDBACK , USE_DEFAULT_FEEDBACK_LED_PIN ) ; // Specify send pin and enable feedback LED at default feedback LED pin
2022-11-14 22:00:43 +08:00
Serial . println ( F ( " Send IR signals at pin 3 " ) ) ;
2021-04-11 08:03:27 +08:00
# endif
2021-01-17 02:50:36 +08:00
2022-01-27 01:36:50 +08:00
# if !defined(SEND_PWM_BY_TIMER)
2021-03-06 08:21:46 +08:00
/*
2023-02-10 07:08:28 +08:00
* Print internal software PWM signal generation info
2021-03-06 08:21:46 +08:00
*/
2023-02-10 07:08:28 +08:00
IrSender . enableIROut ( 38 ) ; // Call it with 38 kHz just to initialize the values printed below
2021-03-06 08:21:46 +08:00
Serial . print ( F ( " Send signal mark duration is " ) ) ;
Serial . print ( IrSender . periodOnTimeMicros ) ;
2022-11-22 19:28:10 +08:00
Serial . print ( F ( " us, pulse narrowing correction is " ) ) ;
2021-04-27 03:57:55 +08:00
Serial . print ( IrSender . getPulseCorrectionNanos ( ) ) ;
2021-03-09 04:38:06 +08:00
Serial . print ( F ( " ns, total period is " ) ) ;
2021-03-06 08:21:46 +08:00
Serial . print ( IrSender . periodTimeMicros ) ;
Serial . println ( F ( " us " ) ) ;
# endif
2010-01-23 14:08:26 +08:00
}
2021-01-30 07:50:58 +08:00
/*
* 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 .
*/
2020-12-31 11:51:54 +08:00
uint16_t sAddress = 0x0102 ;
uint8_t sCommand = 0x34 ;
2022-12-27 23:59:32 +08:00
uint16_t s16BitCommand = 0x5634 ;
2020-12-31 11:51:54 +08:00
uint8_t sRepeats = 0 ;
2010-01-23 14:08:26 +08:00
void loop ( ) {
2020-12-31 11:51:54 +08:00
/*
* Print values
*/
Serial . println ( ) ;
Serial . print ( F ( " address=0x " ) ) ;
Serial . print ( sAddress , HEX ) ;
Serial . print ( F ( " command=0x " ) ) ;
Serial . print ( sCommand , HEX ) ;
Serial . print ( F ( " repeats= " ) ) ;
2021-03-09 04:38:06 +08:00
Serial . println ( sRepeats ) ;
Serial . println ( ) ;
2020-12-31 11:51:54 +08:00
Serial . println ( ) ;
2021-03-01 18:41:14 +08:00
Serial . flush ( ) ;
2020-12-31 11:51:54 +08:00
Serial . println ( F ( " Send NEC with 8 bit address " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-01-15 22:57:40 +08:00
IrSender . sendNEC ( sAddress & 0xFF , sCommand , sRepeats ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ; // delay must be greater than 5 ms (RECORD_GAP_MICROS), otherwise the receiver sees it as one long signal
2020-12-31 11:51:54 +08:00
Serial . println ( F ( " Send NEC with 16 bit address " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-01-15 22:57:40 +08:00
IrSender . sendNEC ( sAddress , sCommand , sRepeats ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2020-12-31 11:51:54 +08:00
2023-02-24 09:40:21 +08:00
Serial . println ( F ( " Send NEC2 with 16 bit address " ) ) ;
Serial . flush ( ) ;
IrSender . sendNEC2 ( sAddress , sCommand , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2021-01-22 04:02:29 +08:00
if ( sRepeats = = 0 ) {
2022-11-22 19:28:10 +08:00
# if FLASHEND >= 0x3FFF && (RAMEND >= 0x4FF || RAMSIZE >= 0x4FF) // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
2021-01-22 04:02:29 +08:00
/*
* Send constant values only once in this demo
*/
Serial . println ( F ( " Sending NEC Pronto data with 8 bit address 0x80 and command 0x45 and no repeats " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-01-22 04:02:29 +08:00
IrSender . sendPronto ( F ( " 0000 006D 0022 0000 015E 00AB " /* Pronto header + start bit */
" 0017 0015 0017 0015 0017 0017 0015 0017 0017 0015 0017 0015 0017 0015 0017 003F " /* Lower address byte */
" 0017 003F 0017 003E 0017 003F 0015 003F 0017 003E 0017 003F 0017 003E 0017 0015 " /* Upper address byte (inverted at 8 bit mode) */
" 0017 003E 0017 0015 0017 003F 0017 0015 0017 0015 0017 0015 0017 003F 0017 0015 " /* command byte */
" 0019 0013 0019 003C 0017 0015 0017 003F 0017 003E 0017 003F 0017 0015 0017 003E " /* inverted command byte */
" 0017 0806 " ) , 0 ) ; //stop bit, no repeat possible, because of missing repeat pattern
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2021-09-07 05:09:48 +08:00
2022-08-31 20:07:41 +08:00
/*
* ! ! ! The next data occupies 136 bytes RAM ! ! !
*/
2023-02-24 09:40:21 +08:00
Serial . println (
F ( " Send NEC sendRaw data with 8 bit address=0xFB04 and command 0x08 and exact timing (16 bit array format) " ) ) ;
2021-09-07 05:09:48 +08:00
Serial . flush ( ) ;
const uint16_t irSignal [ ] = { 9000 , 4500 /*Start bit*/ , 560 , 560 , 560 , 560 , 560 , 1690 , 560 ,
2021-09-28 05:46:13 +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
2021-09-07 05:09:48 +08:00
IrSender . sendRaw ( irSignal , sizeof ( irSignal ) / sizeof ( irSignal [ 0 ] ) , NEC_KHZ ) ; // Note the approach used to automatically calculate the size of the array.
delay ( DELAY_AFTER_SEND ) ;
2023-02-24 09:40:21 +08:00
2021-02-02 18:27:44 +08:00
/*
2021-04-08 07:51:03 +08:00
* With sendNECRaw ( ) you can send 32 bit combined codes
2021-02-02 18:27:44 +08:00
*/
2022-08-31 19:25:29 +08:00
Serial . println ( F ( " Send ONKYO with 16 bit address 0x0102 and 16 bit command 0x0304 with NECRaw(0x03040102) " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-04-08 07:51:03 +08:00
IrSender . sendNECRaw ( 0x03040102 , sRepeats ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2021-02-02 18:27:44 +08:00
/*
* With Send sendNECMSB ( ) you can send your old 32 bit codes .
* To convert one into the other , you must reverse the byte positions and then reverse all positions of each byte .
* Example :
* 0xCB340102 byte reverse - > 0x020134CB bit reverse - > 40802 CD3
*/
2023-02-24 09:40:21 +08:00
Serial . println ( F ( " Send ONKYO with 16 bit address 0x0102 and command 0x34 with old 32 bit format MSB first (0x40802CD3) " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-02-02 18:27:44 +08:00
IrSender . sendNECMSB ( 0x40802CD3 , 32 , false ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2023-02-24 09:40:21 +08:00
# endif
2022-07-12 17:46:04 +08:00
2022-08-31 19:25:29 +08:00
Serial . println ( F ( " Send Panasonic 0xB, 0x10 as 48 bit PulseDistance using ProtocolConstants " ) ) ;
Serial . flush ( ) ;
2022-11-22 19:28:10 +08:00
# if __INT_WIDTH__ < 32
IRRawDataType tRawData [ ] = { 0xB02002 , 0xA010 } ; // LSB of tRawData[0] is sent first
2022-08-31 19:25:29 +08:00
IrSender . sendPulseDistanceWidthFromArray ( & KaseikyoProtocolConstants , & tRawData [ 0 ] , 48 , NO_REPEATS ) ; // Panasonic is a Kaseikyo variant
2022-11-22 19:28:10 +08:00
# else
IrSender . sendPulseDistanceWidth ( & KaseikyoProtocolConstants , 0xA010B02002 , 48 , NO_REPEATS ) ; // Panasonic is a Kaseikyo variant
# endif
2022-08-31 19:25:29 +08:00
delay ( DELAY_AFTER_SEND ) ;
2022-07-12 17:46:04 +08:00
/*
2022-08-28 02:22:58 +08:00
* Send 2 Panasonic 48 bit codes as generic Pulse Distance data , once with LSB and once with MSB first
2022-07-12 17:46:04 +08:00
*/
2022-08-28 02:22:58 +08:00
Serial . println ( F ( " Send Panasonic 0xB, 0x10 as generic 48 bit PulseDistance " ) ) ;
2022-07-12 17:46:04 +08:00
Serial . println ( F ( " LSB first " ) ) ;
Serial . flush ( ) ;
2022-11-22 19:28:10 +08:00
# if __INT_WIDTH__ < 32
2023-02-24 09:40:21 +08:00
IrSender . sendPulseDistanceWidthFromArray ( 38 , 3450 , 1700 , 450 , 1250 , 450 , 400 , & tRawData [ 0 ] , 48 ,
PROTOCOL_IS_LSB_FIRST , 0 , NO_REPEATS ) ;
2022-11-22 19:28:10 +08:00
# else
IrSender . sendPulseDistanceWidth ( 38 , 3450 , 1700 , 450 , 1250 , 450 , 400 , 0xA010B02002 , 48 , PROTOCOL_IS_LSB_FIRST ,
2023-02-24 09:40:21 +08:00
0 , NO_REPEATS ) ;
2022-11-22 19:28:10 +08:00
# endif
2022-07-12 17:46:04 +08:00
delay ( DELAY_AFTER_SEND ) ;
2022-08-28 02:22:58 +08:00
// The same with MSB first. Use bit reversed raw data of LSB first part
2022-07-12 17:46:04 +08:00
Serial . println ( F ( " MSB first " ) ) ;
2022-11-22 19:28:10 +08:00
# if __INT_WIDTH__ < 32
2022-08-28 02:22:58 +08:00
tRawData [ 0 ] = 0x40040D00 ; // MSB of tRawData[0] is sent first
2022-07-12 17:46:04 +08:00
tRawData [ 1 ] = 0x805 ;
2023-02-24 09:40:21 +08:00
IrSender . sendPulseDistanceWidthFromArray ( 38 , 3450 , 1700 , 450 , 1250 , 450 , 400 , & tRawData [ 0 ] , 48 ,
PROTOCOL_IS_MSB_FIRST , 0 , NO_REPEATS ) ;
2022-11-22 19:28:10 +08:00
# else
IrSender . sendPulseDistanceWidth ( 38 , 3450 , 1700 , 450 , 1250 , 450 , 400 , 0x40040D000805 , 48 , PROTOCOL_IS_MSB_FIRST ,
2023-02-24 09:40:21 +08:00
0 , NO_REPEATS ) ;
2022-11-22 19:28:10 +08:00
# endif
2022-07-12 17:46:04 +08:00
delay ( DELAY_AFTER_SEND ) ;
2022-10-12 23:57:57 +08:00
2023-02-24 09:40:21 +08:00
Serial . println ( F ( " Send generic 72 bit PulseDistance 0x5A AFEDCBA9 87654321 LSB first " ) ) ;
2022-10-12 23:57:57 +08:00
Serial . flush ( ) ;
2023-02-24 09:40:21 +08:00
# if __INT_WIDTH__ < 32
2022-11-22 19:28:10 +08:00
tRawData [ 0 ] = 0x87654321 ; // LSB of tRawData[0] is sent first
2023-02-24 09:40:21 +08:00
tRawData [ 1 ] = 0xAFEDCBA9 ;
tRawData [ 2 ] = 0x5A ;
IrSender . sendPulseDistanceWidthFromArray ( 38 , 8900 , 4450 , 550 , 1700 , 550 , 600 , & tRawData [ 0 ] , 72 , PROTOCOL_IS_LSB_FIRST , 0 ,
NO_REPEATS ) ;
# else
IRRawDataType tRawData [ ] = { 0xAFEDCBA987654321 , 0x5A } ; // LSB of tRawData[0] is sent first
IrSender . sendPulseDistanceWidthFromArray ( 38 , 8900 , 4450 , 550 , 1700 , 550 , 600 , & tRawData [ 0 ] , 72 , PROTOCOL_IS_LSB_FIRST , 0 , NO_REPEATS ) ;
# endif
2022-11-22 19:28:10 +08:00
delay ( DELAY_AFTER_SEND ) ;
Serial . println ( F ( " Send generic 52 bit PulseDistanceWidth 0xDCBA9 87654321 LSB first " ) ) ;
Serial . flush ( ) ;
// Real PulseDistanceWidth (constant bit length) does not require a stop bit
# if __INT_WIDTH__ < 32
2023-02-24 09:40:21 +08:00
IrSender . sendPulseDistanceWidthFromArray ( 38 , 300 , 600 , 600 , 300 , 300 , 600 , & tRawData [ 0 ] , 52 ,
PROTOCOL_IS_LSB_FIRST , 0 , 0 ) ;
2022-11-22 19:28:10 +08:00
# else
IrSender . sendPulseDistanceWidth ( 38 , 300 , 600 , 600 , 300 , 300 , 600 , 0xDCBA987654321 , 52 , PROTOCOL_IS_LSB_FIRST ,
2023-02-24 09:40:21 +08:00
0 , 0 ) ;
2022-11-22 19:28:10 +08:00
# endif
2022-10-12 23:57:57 +08:00
delay ( DELAY_AFTER_SEND ) ;
2023-02-24 09:40:21 +08:00
Serial . println ( F ( " Send generic 32 bit PulseWidth 0x87654321 LSB first " ) ) ;
Serial . flush ( ) ;
// Real PulseDistanceWidth (constant bit length) does not require a stop bit
IrSender . sendPulseDistanceWidth ( 38 , 1000 , 500 , 600 , 300 , 300 , 300 , 0x87654321 , 32 , PROTOCOL_IS_LSB_FIRST , 0 , 0 ) ;
delay ( DELAY_AFTER_SEND ) ;
2021-01-22 04:02:29 +08:00
}
2021-01-14 22:28:34 +08:00
2021-04-08 07:51:03 +08:00
Serial . println ( F ( " Send Onkyo (NEC with 16 bit command) " ) ) ;
Serial . flush ( ) ;
2022-12-27 23:59:32 +08:00
IrSender . sendOnkyo ( sAddress , s16BitCommand , sRepeats ) ;
2021-04-08 07:51:03 +08:00
delay ( DELAY_AFTER_SEND ) ;
2021-02-08 22:53:03 +08:00
Serial . println ( F ( " Send Apple " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendApple ( sAddress & 0xFF , sCommand , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2021-02-08 22:53:03 +08:00
2020-12-31 11:51:54 +08:00
Serial . println ( F ( " Send Panasonic " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendPanasonic ( sAddress & 0xFFF , sCommand , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2020-12-31 11:51:54 +08:00
2021-01-02 09:05:20 +08:00
Serial . println ( F ( " Send Kaseikyo with 0x4711 as Vendor ID " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendKaseikyo ( sAddress & 0xFFF , sCommand , sRepeats , 0x4711 ) ;
delay ( DELAY_AFTER_SEND ) ;
2020-12-31 11:51:54 +08:00
2021-09-24 22:12:37 +08:00
Serial . println ( F ( " Send Kaseikyo_Denon variant " ) ) ;
Serial . flush ( ) ;
IrSender . sendKaseikyo_Denon ( sAddress & 0xFFF , sCommand , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2020-12-31 11:51:54 +08:00
Serial . println ( F ( " Send Denon " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendDenon ( sAddress & 0x1F , sCommand , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2020-12-31 11:51:54 +08:00
Serial . println ( F ( " Send Denon/Sharp variant " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendSharp ( sAddress & 0x1F , sCommand , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2020-12-31 11:51:54 +08:00
Serial . println ( F ( " Send Sony/SIRCS with 7 command and 5 address bits " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendSony ( sAddress & 0x1F , sCommand & 0x7F , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2020-12-31 11:51:54 +08:00
2021-03-02 04:27:49 +08:00
Serial . println ( F ( " Send Sony/SIRCS with 7 command and 8 address bits " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendSony ( sAddress & 0xFF , sCommand , sRepeats , SIRCS_15_PROTOCOL ) ;
delay ( DELAY_AFTER_SEND ) ;
2021-03-02 04:27:49 +08:00
2021-01-04 09:54:10 +08:00
Serial . println ( F ( " Send Sony/SIRCS with 7 command and 13 address bits " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendSony ( sAddress & 0x1FFF , sCommand & 0x7F , sRepeats , SIRCS_20_PROTOCOL ) ;
delay ( DELAY_AFTER_SEND ) ;
2021-01-14 10:12:57 +08:00
2022-12-27 23:59:32 +08:00
Serial . println ( F ( " Send Samsung 8 bit command " ) ) ;
Serial . flush ( ) ;
IrSender . sendSamsung ( sAddress , sCommand , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
Serial . println ( F ( " Send Samsung 16 bit command " ) ) ;
Serial . flush ( ) ;
IrSender . sendSamsung ( sAddress , s16BitCommand , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
Serial . println ( F ( " Send Samsung48 16 bit command " ) ) ;
Serial . flush ( ) ;
IrSender . sendSamsung48 ( sAddress , s16BitCommand , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2021-01-14 10:12:57 +08:00
Serial . println ( F ( " Send RC5 " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendRC5 ( sAddress & 0x1F , sCommand & 0x3F , sRepeats , true ) ; // 5 address, 6 command bits
delay ( DELAY_AFTER_SEND ) ;
2021-01-14 10:12:57 +08:00
2021-03-09 04:38:06 +08:00
Serial . println ( F ( " Send RC5X with 7.th MSB of command set " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-03-09 04:38:06 +08:00
IrSender . sendRC5 ( sAddress & 0x1F , ( sCommand & 0x3F ) + 0x40 , sRepeats , true ) ; // 5 address, 7 command bits
delay ( DELAY_AFTER_SEND ) ;
2021-01-14 10:12:57 +08:00
Serial . println ( F ( " Send RC6 " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-01-15 22:57:40 +08:00
IrSender . sendRC6 ( sAddress , sCommand , sRepeats , true ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2020-12-31 11:51:54 +08:00
2022-11-22 19:28:10 +08:00
# if FLASHEND >= 0x3FFF && (RAMEND >= 0x4FF || RAMSIZE >= 0x4FF) // For 16k flash or more, like ATtiny1604. Code does not fit in program memory of ATtiny85 etc.
2021-01-28 00:28:44 +08:00
/*
* Next example how to use the IrSender . write function
*/
IRData IRSendData ;
// prepare data
IRSendData . address = sAddress ;
IRSendData . command = sCommand ;
IRSendData . flags = IRDATA_FLAGS_EMPTY ;
IRSendData . protocol = SAMSUNG ;
Serial . print ( F ( " Send " ) ) ;
Serial . println ( getProtocolString ( IRSendData . protocol ) ) ;
2022-01-27 01:36:50 +08:00
Serial . flush ( ) ;
2021-01-28 00:28:44 +08:00
IrSender . write ( & IRSendData , sRepeats ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2021-01-04 09:54:10 +08:00
2021-01-28 00:28:44 +08:00
IRSendData . protocol = JVC ; // switch protocol
Serial . print ( F ( " Send " ) ) ;
Serial . println ( getProtocolString ( IRSendData . protocol ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-01-28 00:28:44 +08:00
IrSender . write ( & IRSendData , sRepeats ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2021-01-05 00:15:03 +08:00
2022-12-27 23:59:32 +08:00
IRSendData . command = s16BitCommand ; // LG support more than 8 bit command
2022-11-12 08:31:03 +08:00
IRSendData . protocol = SAMSUNG ;
Serial . print ( F ( " Send " ) ) ;
Serial . println ( getProtocolString ( IRSendData . protocol ) ) ;
Serial . flush ( ) ;
IrSender . write ( & IRSendData , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2022-09-15 15:54:09 +08:00
2021-01-28 00:28:44 +08:00
IRSendData . protocol = LG ;
Serial . print ( F ( " Send " ) ) ;
Serial . println ( getProtocolString ( IRSendData . protocol ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-01-28 00:28:44 +08:00
IrSender . write ( & IRSendData , sRepeats ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2021-01-18 07:41:37 +08:00
2022-09-15 15:54:09 +08:00
Serial . println ( F ( " Send MagiQuest " ) ) ;
Serial . flush ( ) ;
2022-12-27 23:59:32 +08:00
IrSender . sendMagiQuest ( 0x6BCD0000 | ( uint32_t ) sAddress , s16BitCommand ) ; // we have 31 bit address
2022-09-15 15:54:09 +08:00
delay ( DELAY_AFTER_SEND ) ;
2022-10-12 23:57:57 +08:00
// Bang&Olufsen must be sent with 455 kHz
2023-02-24 09:40:21 +08:00
// Serial.println(F("Send Bang&Olufsen"));
// Serial.flush();
// IrSender.sendBangOlufsen(sAddress, sCommand, sRepeats);
// delay(DELAY_AFTER_SEND);
2022-10-02 16:00:58 +08:00
2021-01-28 00:28:44 +08:00
IRSendData . protocol = BOSEWAVE ;
Serial . println ( F ( " Send Bosewave with no address and 8 command bits " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-01-28 00:28:44 +08:00
IrSender . write ( & IRSendData , sRepeats ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2021-01-02 09:05:20 +08:00
2023-02-24 09:40:21 +08:00
IRSendData . protocol = FAST ;
Serial . print ( F ( " Send " ) ) ;
Serial . println ( getProtocolString ( IRSendData . protocol ) ) ;
Serial . flush ( ) ;
IrSender . write ( & IRSendData , sRepeats ) ;
delay ( DELAY_AFTER_SEND ) ;
2021-01-13 10:06:19 +08:00
/*
2021-01-15 22:57:40 +08:00
* LEGO is difficult to receive because of its short marks and spaces
2021-01-13 10:06:19 +08:00
*/
2021-01-02 09:05:20 +08:00
Serial . println ( F ( " Send Lego with 2 channel and with 4 command bits " ) ) ;
2021-03-22 21:32:09 +08:00
Serial . flush ( ) ;
2021-01-15 22:57:40 +08:00
IrSender . sendLegoPowerFunctions ( sAddress , sCommand , LEGO_MODE_COMBO , true ) ;
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2021-01-02 09:05:20 +08:00
2021-05-02 04:24:04 +08:00
# endif // FLASHEND
2021-01-17 02:50:36 +08:00
/*
* Force buffer overflow
*/
2023-02-24 09:40:21 +08:00
Serial . println ( F ( " Force buffer overflow by sending 700 marks and spaces " ) ) ;
for ( unsigned int i = 0 ; i < 350 ; + + i ) {
2021-11-03 13:57:27 +08:00
// 400 + 400 should be received as 8/8 and sometimes as 9/7 or 7/9 if compensation by MARK_EXCESS_MICROS is optimal.
// 210 + 540 = 750 should be received as 5/10 or 4/11 if compensation by MARK_EXCESS_MICROS is optimal.
IrSender . mark ( 210 ) ; // 8 pulses at 38 kHz
IrSender . space ( 540 ) ; // to fill up to 750 us
2021-01-17 02:50:36 +08:00
}
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_SEND ) ;
2021-01-17 02:50:36 +08:00
2020-12-31 11:51:54 +08:00
/*
* Increment values
2021-01-30 07:50:58 +08:00
* Also increment address just for demonstration , which normally makes no sense
2020-12-31 11:51:54 +08:00
*/
sAddress + = 0x0101 ;
sCommand + = 0x11 ;
2022-12-27 23:59:32 +08:00
s16BitCommand + = 0x1111 ;
2020-12-31 11:51:54 +08:00
sRepeats + + ;
2021-01-13 18:53:33 +08:00
// clip repeats at 4
if ( sRepeats > 4 ) {
sRepeats = 4 ;
2020-06-01 09:47:09 +08:00
}
2021-03-09 08:31:31 +08:00
2021-03-09 04:38:06 +08:00
delay ( DELAY_AFTER_LOOP ) ; // additional delay at the end of each loop
2010-01-23 14:08:26 +08:00
}
2021-11-03 13:57:27 +08:00