ESP32 code speed depends on "Classic Bluetooth" client connection/disconnection?
Posted: Sun May 03, 2020 6:22 am
Hello everyone
I am trying to make a code to control the intensity of incandescent lamp (AC voltage). I use a signal zero cross circuit to synchronize the signal control of the ac load. The value of the intensity is given by a bluetooth device (android). The initial intensity is 50%. My code is the following:
First when android device is disconnected, the code runs normally even when the intensity of the incandescent lamp is 50%, I mean that the incandescent lamp does not show any visible noise and the intensity is so continuous. BUT when I pair the android device with the ESP32 (via bluetooth), the intensity seems like something injects noise but it still communicating. So I don't know how to fix it. Because the code I put above is the same that i worked with a HC05
I am trying to make a code to control the intensity of incandescent lamp (AC voltage). I use a signal zero cross circuit to synchronize the signal control of the ac load. The value of the intensity is given by a bluetooth device (android). The initial intensity is 50%. My code is the following:
Code: Select all
#include "BluetoothSerial.h"
BluetoothSerial SerialBT;
short eValvula=4;
short OPTO = 34;
float intensity;
unsigned long shooting_time = 8333;
double t1, t1_1;
long tiempoBLE_1=0;
void setup()
{
//Serial.begin(115200);
SerialBT.begin("Chi"); //Bluetooth device name
pinMode(eValvula,OUTPUT);
pinMode(OPTO, INPUT);
}
void loop()
{
if (SerialBT.available())
{
intensity=SerialBT.parseFloat();
}
shooting_time = map(intensity, 0, 100, 8333, 0);
if (digitalRead(OPTO)==1)
{
digitalWrite(eValvula, LOW);
//SerialBT.println(t1-t1_1);
// SerialBT.print(" ");
// SerialBT.println(intensity);
t1_1 = micros();
}
t1 = micros();
if ((abs(t1 - t1_1) >= shooting_time) && (abs(t1 - t1_1) <= 8333))
{
digitalWrite(eValvula, HIGH);
}
else
{
digitalWrite(eValvula, LOW);
}
if(millis()-tiempoBLE_1>7)
{
tiempoBLE_1=millis();
SerialBT.println(tiempoBLE_1-millis());
}
}