feat: implement simple IR transceiver

This commit is contained in:
Fritz Heiden 2024-11-22 10:35:49 +01:00
parent af51e587bf
commit 1990f1c28c

View File

@ -1,13 +1,49 @@
#include <Arduino.h>
const int IR_SEND_PIN = 12; // GPIO12 for the IR LED
#include <IRremote.hpp>
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: