|
| 1 | +// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +/* |
| 6 | + * Based on the SimpleReceiver.cpp and SimpleSender.cpp from the |
| 7 | + * Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote. |
| 8 | + * by Armin Joachimsmeyer |
| 9 | + ************************************************************************************ |
| 10 | + * MIT License |
| 11 | + * |
| 12 | + * Copyright (c) 2020-2023 Armin Joachimsmeyer |
| 13 | + * |
| 14 | + */ |
| 15 | + |
| 16 | +#include <Arduino.h> |
| 17 | + |
| 18 | +#include <IRremote.hpp> // include the library |
| 19 | +#define IR_RECEIVE_PIN 5 |
| 20 | +#define IR_SEND_PIN 6 |
| 21 | + |
| 22 | +void setup() { |
| 23 | + Serial.begin(115200); |
| 24 | + while (!Serial) |
| 25 | + ; |
| 26 | + Serial.println("Adafruit STEMMA IR Transceiver Demo"); |
| 27 | + IrReceiver.begin(IR_RECEIVE_PIN); |
| 28 | + IrSender.begin(IR_SEND_PIN); // Start with IR_SEND_PIN -which is defined in PinDefinitionsAndMore.h- as send pin and enable feedback LED at default feedback LED pin |
| 29 | + Serial.print("IRin on pin "); |
| 30 | + Serial.print(IR_RECEIVE_PIN); |
| 31 | + Serial.print(", IRout on pin "); |
| 32 | + Serial.println(IR_SEND_PIN); |
| 33 | +} |
| 34 | + |
| 35 | +uint8_t sCommand = 0x34; |
| 36 | +uint8_t sRepeats = 0; |
| 37 | + |
| 38 | +void loop() { |
| 39 | + /* |
| 40 | + * Check if received data is available and if yes, try to decode it. |
| 41 | + * Decoded result is in the IrReceiver.decodedIRData structure. |
| 42 | + * |
| 43 | + * E.g. command is in IrReceiver.decodedIRData.command |
| 44 | + * address is in command is in IrReceiver.decodedIRData.address |
| 45 | + * and up to 32 bit raw data in IrReceiver.decodedIRData.decodedRawData |
| 46 | + */ |
| 47 | + if (IrReceiver.decode()) { |
| 48 | + if (IrReceiver.decodedIRData.protocol == UNKNOWN) { |
| 49 | + IrReceiver.printIRResultRawFormatted(&Serial, true); |
| 50 | + IrReceiver.resume(); |
| 51 | + } else { |
| 52 | + IrReceiver.resume(); |
| 53 | + IrReceiver.printIRResultShort(&Serial); |
| 54 | + IrReceiver.printIRSendUsage(&Serial); |
| 55 | + delay(1000); |
| 56 | + Serial.println("Sending received command.."); |
| 57 | + IrSender.sendNEC(IrReceiver.lastDecodedProtocol, IrReceiver.lastDecodedCommand, IrReceiver.repeatCount); |
| 58 | + delay(1000); |
| 59 | + Serial.print("Sent!"); |
| 60 | + //Serial.println(IrReceiver.lastDecodedProtocol, IrReceiver.lastDecodedCommand, IrReceiver.repeatCount); |
| 61 | + } |
| 62 | + Serial.println(); |
| 63 | + } |
| 64 | +} |
0 commit comments