SO I have an ESP32 and BLA423 sensor. I can run this simple code in the loop and continuously access the sensor value in and display it in the serial terminal.
int a =0;
void loop()
{
sensor->getAccel(acc);
if( a<5000 && sensor->getAccel(acc) == true)
{
snprintf(report, sizeof(report),"%d,%d,%d",acc.x, acc.y, acc.z);
Serial.println(report);
//SerialBT.println(report);
a++;
}
}
But I want to start displaying the accelerometer value when I send "Start" from serial and stop displaying when I send "Stop".
However, if I create something like this in the loop function
sensor->getAccel(acc);
if (SerialBT.available())
{
char incomingChar = SerialBT.read();
if (incomingChar == '1')
{
if( a<5000 && sensor->getAccel(acc) == true)
{
snprintf(report, sizeof(report),"%d,%d,%d",acc.x, acc.y, acc.z);
Serial.println(report);
//SerialBT.println(report);
a++;
}
}
}
I need to enter the Start every loop.
Also if I create some function
void loopThis()
{
int a =0;
bool y = true;
sensor->getAccel(acc);
for (int a = 0; a <100; a++)
{
snprintf(report, sizeof(report),"%d,%d,%d",acc.x, acc.y, acc.z);
Serial.println(report);
SerialBT.println(report);
a++;
//delay(1000);
}
//Serial.println(a);
}
and run this function in loop()
it will only display a single value in a loop.
TLDR: I want to start displaying the accelerometer value when I send "Start" from the Serial Monitor and keep on displaying until I send "Stop" to the ESP32 from the Serial Monitor.