feat: implement simple IR transceiver
This commit is contained in:
parent
af51e587bf
commit
1990f1c28c
36
src/main.cpp
36
src/main.cpp
@ -1,13 +1,49 @@
|
|||||||
#include <Arduino.h>
|
#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:
|
// put function declarations here:
|
||||||
int myFunction(int, int);
|
int myFunction(int, int);
|
||||||
|
void parallelLoop(void *pvParameters);
|
||||||
|
|
||||||
void setup()
|
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()
|
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:
|
// put function definitions here:
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user