//Librería para bluetooth
#include <BluetoothSerial.h>
//Condición de conexión
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth no disponible
#endif
//Definir el pin del LED
#define LED_BT 13
#define BTN_BT 4
//Crear objeto Bluetooth
BluetoothSerial SerialBT;
void setup() {
//Iniciar el bluetooth con el nombre establecido
SerialBT.begin("ESP_ELDA");
pinMode(LED_BT, OUTPUT);
pinMode(BTN_BT, INPUT_PULLUP);
}
void loop() {
//Pregunta si hay datos en el buffer
if (SerialBT.available() > 0) {
//Si hay datos lo almacena y compara
char dato = SerialBT.read();
if (dato == 'A')
digitalWrite(LED_BT, HIGH);
if (dato == 'B')
digitalWrite(LED_BT, LOW);
}
//Se envía el estado del botón
if (digitalRead(BTN_BT) == 0) {
SerialBT.print("E");
delay(200);
} else {
SerialBT.print("T");
delay(200);
}
}