#include "BluetoothSerial.h" #if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED) #error Bluetooth is not enabled! Please run `make menuconfig` to and enable it #endif int salida = 15; //Variables de control y/o lectura char valor; String readString; BluetoothSerial SerialBT; // setting PWM properties const int freq = 5000; const int ledChannel = 0; const int resolution = 8; void setup() { // configure LED PWM functionalitites ledcSetup(ledChannel, freq, resolution); // attach the channel to the GPIO to be controlled ledcAttachPin(salida, ledChannel); pinMode(salida, OUTPUT); Serial.begin(9600); SerialBT.begin("RAFAB"); //Bluetooth device name Serial.println("The device started, now you can pair it with bluetooth!"); } void loop() { char dato =SerialBT.read(); switch(dato) { case 'A' :intensidad(); break; } } void intensidad(){ delay(15); while (SerialBT.available()){ char C = SerialBT.read(); readString += C; } if (readString.length()>0){ ledcWrite(ledChannel,(readString.toInt())); readString = ""; } }