Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This sketch combines sending and receiving.
- #include <Arduino.h>
- #include <IrReceiverSampler.h>
- #include <IrSenderPwm.h>
- static constexpr pin_t RECEIVE_PIN = 8U;
- static constexpr size_t BUFFERSIZE = 200U;
- static constexpr uint32_t BAUD = 115200UL;
- // NEC(1) 122 29 with no repetition; powers on many Yamaha receivers
- static const microseconds_t array[]
- #if HAS_FLASH_READ
- PROGMEM
- #endif
- = {
- 9024, 4512, 564, 564, 564, 1692, 564, 564, 564, 1692, 564, 1692,
- 564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 564, 564, 1692,
- 564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564,
- 564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564,
- 564, 564, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 1692, 564,
- 1692, 564, 1692, 564, 39756
- };
- static const IrSequence* irSequence =
- #if HAS_FLASH_READ
- IrSequence::readFlash(array, sizeof (array) / sizeof (microseconds_t));
- #else
- new IrSequence(array, sizeof (array) / sizeof (microseconds_t));
- #endif
- static IrReceiver *receiver;
- static IrSender *sender;
- void setup() {
- Serial.begin(BAUD);
- while(!Serial);
- receiver = IrReceiverSampler::newIrReceiverSampler(BUFFERSIZE, RECEIVE_PIN);
- sender = IrSenderPwm::getInstance(true);
- Serial.println(F("Listening!"));
- receiver->enable();
- }
- void loop() {
- if (Serial.read() != -1) {
- #if HAS_FLASH_READ
- Serial.println(F("Sending a signal from PROGMEM!"));
- #else
- Serial.println(F("Sending a signal!"));
- #endif
- sender->send(*irSequence, 56000U);
- }
- receiver->receive(); // combines enable, loop, disable
- if (receiver->isEmpty()) {
- Serial.println(F("No data."));
- } else {
- receiver->dump(Serial);
- Serial.println();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement