I've just started with ESP32 and I already have a base knowledge from Arduino, so I jumped to Bluetooth and tried a simple ON/OFF button. My problem is that I can't hold the LED turned ON, it shutdown itself for no reason. I might be doing something wrong with uploading things or misundertanding how ESP32 works. I'll leave the code here, really simple
#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
#define LED 16
BluetoothSerial SerialBT;
void setup() {
pinMode (LED, OUTPUT);
Serial.begin(115200);
SerialBT.begin("ESP32test"); //Bluetooth device name
Serial.println("The device started, now you can pair it with bluetooth!");
}
void loop() {
while (SerialBT.available())
{
int value = SerialBT.parseInt();
Serial.println (value); //Debug, ignore
digitalWrite (LED, value);
}
delay(20);
}
EDIT:
By directly debugging from SerialBT.read(), turns out that it sends "-1-1-1-1-1-1-1-1", which "parseInt" reads as 0 every second, so now my question is: How do I ignore it?