From 1990f1c28cdd1bbbf218e3cac62c69a77a152da1 Mon Sep 17 00:00:00 2001 From: Fritz Heiden Date: Fri, 22 Nov 2024 10:35:49 +0100 Subject: [PATCH] feat: implement simple IR transceiver --- src/main.cpp | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 1d68131..eb16762 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,13 +1,49 @@ #include +const int IR_SEND_PIN = 12; // GPIO12 for the IR LED +#include + +const int ReceiverPin = 14; // GPIO14 for the IR receiver (TSOP48) +const int LedPin = 13; // GPIO13 for the external LED + +IRData data; + + // put function declarations here: int myFunction(int, int); +void parallelLoop(void *pvParameters); void setup() { + Serial.begin(115200); // Start the serial communication + pinMode(LedPin, OUTPUT); // Set LED pin as output + pinMode(IR_SEND_PIN, OUTPUT); // Set IR LED pin as output + IrReceiver.begin(ReceiverPin, DISABLE_LED_FEEDBACK); // Initialize the IR receiver + Serial.println("IR Receiver Ready!"); + xTaskCreate(parallelLoop, "parallelLoop", 2048, NULL, 1, NULL); // Create a task for parallel loop } void loop() { + if (IrReceiver.decode()) + { // Check if IR signal is received + IrReceiver.printIRResultShort(&Serial); // Print IR signal details to Serial Monitor + data = IrReceiver.decodedIRData; + digitalWrite(LedPin, HIGH); // Turn on the LED + delay(200); // Keep LED on for 200ms + digitalWrite(LedPin, LOW); // Turn off the LED + IrReceiver.resume(); // Prepare to receive the next IR signal + } +} + +void parallelLoop(void *pvParameters) +{ + while (true) + { + delay(5000); + digitalWrite(IR_SEND_PIN, HIGH); + delay(5000); + digitalWrite(IR_SEND_PIN, LOW); + } } // put function definitions here: