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: