Merge pull request #2795 from adafruit/ir_demod
Adding IR demodulator examples
This commit is contained in:
commit
fd34db74c6
2 changed files with 95 additions and 0 deletions
|
|
@ -0,0 +1,64 @@
|
|||
// SPDX-FileCopyrightText: 2024 Liz Clark for Adafruit Industries
|
||||
//
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
/*
|
||||
* Based on the ReceiverDump.cpp from the
|
||||
* Arduino-IRremote https://github.com/Arduino-IRremote/Arduino-IRremote.
|
||||
* by Armin Joachimsmeyer
|
||||
************************************************************************************
|
||||
* MIT License
|
||||
*
|
||||
* Copyright (c) 2020-2023 Armin Joachimsmeyer
|
||||
*
|
||||
*/
|
||||
|
||||
#include <Arduino.h>
|
||||
#include <IRremote.hpp>
|
||||
|
||||
#define IR_RECEIVE_PIN 5
|
||||
#define MARK_EXCESS_MICROS 20 // Adapt it to your IR receiver module. 20 is recommended for the cheap VS1838 modules.
|
||||
|
||||
int ir_count = 0;
|
||||
bool ir_state = false;
|
||||
|
||||
void setup() {
|
||||
pinMode(LED_BUILTIN, OUTPUT);
|
||||
|
||||
Serial.begin(115200);
|
||||
// Start the receiver and if not 3. parameter specified, take LED_BUILTIN pin from the internal boards definition as default feedback LED
|
||||
IrReceiver.begin(IR_RECEIVE_PIN, ENABLE_LED_FEEDBACK);
|
||||
Serial.print(F("Ready to receive IR signals "));
|
||||
Serial.print("at pin ");
|
||||
Serial.println(IR_RECEIVE_PIN);
|
||||
|
||||
}
|
||||
|
||||
void loop() {
|
||||
// put your main code here, to run repeatedly:
|
||||
if (IrReceiver.decode()) { // Grab an IR code
|
||||
// At 115200 baud, printing takes 200 ms for NEC protocol and 70 ms for NEC repeat
|
||||
ir_state = true;
|
||||
Serial.println(); // blank line between entries
|
||||
Serial.println(); // 2 blank lines between entries
|
||||
IrReceiver.printIRResultShort(&Serial);
|
||||
if (IrReceiver.decodedIRData.flags & IRDATA_FLAGS_WAS_OVERFLOW) {
|
||||
Serial.print("Try to increase the \"RAW_BUFFER_LENGTH\" value of ");
|
||||
Serial.println(RAW_BUFFER_LENGTH);
|
||||
// see also https://github.com/Arduino-IRremote/Arduino-IRremote#compile-options--macros-for-this-library
|
||||
} else {
|
||||
Serial.println();
|
||||
Serial.println("IR signal received!");
|
||||
IrReceiver.printIRResultRawFormatted(&Serial, true); // Output the results in RAW format
|
||||
ir_count += 1;
|
||||
Serial.print("Signal count: ");
|
||||
Serial.println(ir_count);
|
||||
Serial.println();
|
||||
}
|
||||
IrReceiver.resume();
|
||||
}
|
||||
else {
|
||||
ir_state = false;
|
||||
}
|
||||
|
||||
}
|
||||
31
STEMMA_IR_Demodulator_Examples/CircuitPython/code.py
Normal file
31
STEMMA_IR_Demodulator_Examples/CircuitPython/code.py
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
# SPDX-FileCopyrightText: Copyright (c) 2024 Liz Clark for Adafruit Industries
|
||||
#
|
||||
# SPDX-License-Identifier: MIT
|
||||
|
||||
import pulseio
|
||||
import board
|
||||
|
||||
pulses = pulseio.PulseIn(board.D5)
|
||||
pulse = False
|
||||
pulse_count = 0
|
||||
|
||||
while True:
|
||||
|
||||
# Wait for an active pulse
|
||||
while len(pulses) == 0:
|
||||
if pulse:
|
||||
pulse = False
|
||||
|
||||
if len(pulses) != 0 and not pulse:
|
||||
pulse_count += 1
|
||||
print(f"pulses detected {pulse_count} times")
|
||||
pulse = True
|
||||
# Pause while we do something with the pulses
|
||||
pulses.pause()
|
||||
# Print the pulses. pulses[0] is an active pulse unless the length
|
||||
# reached max length and idle pulses are recorded.
|
||||
print(pulses[0])
|
||||
# Clear the rest
|
||||
pulses.clear()
|
||||
# Resume with an 80 microsecond active pulse
|
||||
pulses.resume(80)
|
||||
Loading…
Reference in a new issue