From 4dd48ac3f6799d71ae0861c5018e0e23e43b5b3b Mon Sep 17 00:00:00 2001 From: Fritz Heiden Date: Fri, 29 Nov 2024 12:31:58 +0100 Subject: [PATCH] feat: add basic bluetooth communication --- src/main.cpp | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index eb16762..7046e7c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,6 +1,9 @@ #include const int IR_SEND_PIN = 12; // GPIO12 for the IR LED #include +#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) {