feat: add basic bluetooth communication
This commit is contained in:
parent
1990f1c28c
commit
4dd48ac3f6
20
src/main.cpp
20
src/main.cpp
@ -1,6 +1,9 @@
|
|||||||
#include <Arduino.h>
|
#include <Arduino.h>
|
||||||
const int IR_SEND_PIN = 12; // GPIO12 for the IR LED
|
const int IR_SEND_PIN = 12; // GPIO12 for the IR LED
|
||||||
#include <IRremote.hpp>
|
#include <IRremote.hpp>
|
||||||
|
#include "BluetoothSerial.h"
|
||||||
|
|
||||||
|
BluetoothSerial SerialBT;
|
||||||
|
|
||||||
const int ReceiverPin = 14; // GPIO14 for the IR receiver (TSOP48)
|
const int ReceiverPin = 14; // GPIO14 for the IR receiver (TSOP48)
|
||||||
const int LedPin = 13; // GPIO13 for the external LED
|
const int LedPin = 13; // GPIO13 for the external LED
|
||||||
@ -11,15 +14,18 @@ IRData data;
|
|||||||
// put function declarations here:
|
// put function declarations here:
|
||||||
int myFunction(int, int);
|
int myFunction(int, int);
|
||||||
void parallelLoop(void *pvParameters);
|
void parallelLoop(void *pvParameters);
|
||||||
|
void handleSerialBT(void *pvParameters);
|
||||||
|
|
||||||
void setup()
|
void setup()
|
||||||
{
|
{
|
||||||
Serial.begin(115200); // Start the serial communication
|
Serial.begin(115200); // Start the serial communication
|
||||||
|
SerialBT.begin("ESP32");
|
||||||
pinMode(LedPin, OUTPUT); // Set LED pin as output
|
pinMode(LedPin, OUTPUT); // Set LED pin as output
|
||||||
pinMode(IR_SEND_PIN, OUTPUT); // Set IR 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
|
IrReceiver.begin(ReceiverPin, DISABLE_LED_FEEDBACK); // Initialize the IR receiver
|
||||||
Serial.println("IR Receiver Ready!");
|
Serial.println("IR Receiver Ready!");
|
||||||
xTaskCreate(parallelLoop, "parallelLoop", 2048, NULL, 1, NULL); // Create a task for parallel loop
|
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()
|
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:
|
// put function definitions here:
|
||||||
int myFunction(int x, int y)
|
int myFunction(int x, int y)
|
||||||
{
|
{
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user