|
| 1 | +// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries |
| 2 | +// |
| 3 | +// SPDX-License-Identifier: MIT |
| 4 | + |
| 5 | +/* |
| 6 | + * Based on the ReceiverDump.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 | +#include <IRremote.hpp> |
| 18 | + |
| 19 | +#define IR_RECEIVE_PIN 5 |
| 20 | +#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules. |
| 21 | + |
| 22 | +int ir_count = 0; |
| 23 | +bool ir_state = false; |
| 24 | + |
| 25 | +void setup() { |
| 26 | + pinMode(LED_BUILTIN, OUTPUT); |
| 27 | + |
| 28 | + Serial.begin(115200); |
| 29 | + // Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED |
| 30 | + IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK); |
| 31 | + Serial.print(F("Ready to receive IR signals ")); |
| 32 | + Serial.print("at pin "); |
| 33 | + Serial.println(IR_RECEIVE_PIN); |
| 34 | + |
| 35 | +} |
| 36 | + |
| 37 | +void loop() { |
| 38 | + // put your main code here, to run repeatedly: |
| 39 | + if (IrReceiver.decode()) { // Grab an IR code |
| 40 | + // At 115200 baud, printing takes 200 ms for NEC protocol and 70 ms for NEC repeat |
| 41 | + ir_state = true; |
| 42 | + Serial.println(); // blank line between entries |
| 43 | + Serial.println(); // 2 blank lines between entries |
| 44 | + IrReceiver.printIRResultShort(&Serial); |
| 45 | + if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) { |
| 46 | + Serial.print("Try to increase the \"RAW_BUFFER_LENGTH\" value of "); |
| 47 | + Serial.println(RAW_BUFFER_LENGTH); |
| 48 | + // see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library |
| 49 | + } else { |
| 50 | + Serial.println(); |
| 51 | + Serial.println("IR signal received!"); |
| 52 | + IrReceiver.printIRResultRawFormatted(&Serial, true); // Output the results in RAW format |
| 53 | + ir_count += 1; |
| 54 | + Serial.print("Signal count: "); |
| 55 | + Serial.println(ir_count); |
| 56 | + Serial.println(); |
| 57 | + } |
| 58 | + IrReceiver.resume(); |
| 59 | + } |
| 60 | + else { |
| 61 | + ir_state = false; |
| 62 | + } |
| 63 | + |
| 64 | +} |
0 commit comments