Advertisement
Guest User

Untitled

a guest
Aug 14th, 2021
162
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.81 KB | None | 0 0
  1. // This sketch combines sending and receiving.
  2.  
  3. #include <Arduino.h>
  4. #include <IrReceiverSampler.h>
  5. #include <IrSenderPwm.h>
  6.  
  7. static constexpr pin_t RECEIVE_PIN = 8U;
  8. static constexpr size_t BUFFERSIZE = 200U;
  9. static constexpr uint32_t BAUD = 115200UL;
  10.  
  11. // NEC(1) 122 29 with no repetition; powers on many Yamaha receivers
  12. static const microseconds_t array[]
  13. #if HAS_FLASH_READ
  14.         PROGMEM
  15. #endif
  16.         = {
  17.     9024, 4512, 564, 564, 564, 1692, 564, 564, 564, 1692, 564, 1692,
  18.     564, 1692, 564, 1692, 564, 564, 564, 1692, 564, 564, 564, 1692,
  19.     564, 564, 564, 564, 564, 564, 564, 564, 564, 1692, 564, 1692, 564,
  20.     564, 564, 1692, 564, 1692, 564, 1692, 564, 564, 564, 564, 564, 564,
  21.     564, 564, 564, 1692, 564, 564, 564, 564, 564, 564, 564, 1692, 564,
  22.     1692, 564, 1692, 564, 39756
  23. };
  24.  
  25. static const IrSequence* irSequence =
  26. #if HAS_FLASH_READ
  27.         IrSequence::readFlash(array, sizeof (array) / sizeof (microseconds_t));
  28. #else
  29.         new IrSequence(array, sizeof (array) / sizeof (microseconds_t));
  30. #endif
  31. static IrReceiver *receiver;
  32. static IrSender *sender;
  33.  
  34. void setup() {
  35.     Serial.begin(BAUD);
  36.     while(!Serial);
  37.     receiver = IrReceiverSampler::newIrReceiverSampler(BUFFERSIZE, RECEIVE_PIN);
  38.     sender = IrSenderPwm::getInstance(true);
  39.     Serial.println(F("Listening!"));
  40.     receiver->enable();
  41. }
  42.  
  43. void loop() {
  44.  
  45.     if (Serial.read() != -1) {
  46.       #if HAS_FLASH_READ
  47.         Serial.println(F("Sending a signal from PROGMEM!"));
  48.       #else
  49.         Serial.println(F("Sending a signal!"));
  50.       #endif
  51.       sender->send(*irSequence, 56000U);
  52.     }
  53.    
  54.     receiver->receive(); // combines enable, loop, disable
  55.     if (receiver->isEmpty()) {
  56.       Serial.println(F("No data."));
  57.     } else {
  58.       receiver->dump(Serial);
  59.       Serial.println();
  60.     }
  61.    
  62. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement