#include "BluetoothSerial.h" //V_Инсталлирована
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
BluetoothSerial SerialBT;
int received;// received value will be stored in this variable
char receivedChar;// received value will be stored as CHAR in this variable
const char turnON='a', turnOFF='b';
const int LEDpin = 2;
void setup() { Serial.begin(115200); pinMode(LEDpin, OUTPUT);
SerialBT.begin("ESP32_SRINIBAS"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
Serial.println("To turn ON send: a");
Serial.println("To turn OFF send: b"); }
void loop() {
receivedChar =(char)SerialBT.read();
if(Serial.available()) SerialBT.write(Serial.read());
if(SerialBT.available()) {
SerialBT.print("Received:");
SerialBT.println(receivedChar); Serial.print ("Received:");
Serial.println(receivedChar);
//SerialBT.println(receivedChar);//print on the app
//SerialBT.write(receivedChar); //print on serial monitor
if(receivedChar == turnON)
{SerialBT.println("LED ON:"); Serial.println("LED ON:");
digitalWrite(LEDpin, HIGH); }
if(receivedChar == turnOFF)
{SerialBT.println("LED OFF:"); Serial.println("LED OFF:");
digitalWrite(LEDpin, LOW); }
} delay(20);
}