feat: add basic bluetooth communication

This commit is contained in:
Fritz Heiden 2024-11-29 12:31:58 +01:00
parent 1990f1c28c
commit 4dd48ac3f6

View File

@ -1,6 +1,9 @@
#include <Arduino.h>
const int IR_SEND_PIN = 12; // GPIO12 for the IR LED
#include <IRremote.hpp>
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
const int ReceiverPin = 14; // GPIO14 for the IR receiver (TSOP48)
const int LedPin = 13; // GPIO13 for the external LED
@ -11,15 +14,18 @@ IRData data;
// put function declarations here:
int myFunction(int, int);
void parallelLoop(void *pvParameters);
void handleSerialBT(void *pvParameters);
void setup()
{
Serial.begin(115200); // Start the serial communication
SerialBT.begin("ESP32");
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
xTaskCreate(handleSerialBT, "handleSerialBT", 2048, NULL, 1, NULL); // Create a task for serial BT communication
}
void loop()
@ -46,6 +52,20 @@ void parallelLoop(void *pvParameters)
}
}
void handleSerialBT(void *pvParameters)
{
while (true)
{
if (Serial.available()) {
SerialBT.write(Serial.read());
}
if (SerialBT.available()) {
Serial.write(SerialBT.read());
}
delay(25);
}
}
// put function definitions here:
int myFunction(int x, int y)
{