Ejecutar indefinidamente un loop hasta ingresar un nuevo valor

Hola, tengo este problema y quiero saber si me podrían ayudar, estoy haciendo un proyecto el cual lleva este código, el cual se lee mediante Bluetooth, y si la variable es igual a un valor establecido, se ejecutara el programa para que avance, pero solo se ejecuta lo establecido ahí, y quiero saber como puedo hacer para que se ejecute indefinidamente hasta que se vuelva a ingresar la variable con otro valor, agrego mi código.

#include "BluetoothSerial.h"
String device_name = "ESP32-BT-Slave";
#if !defined(CONFIG_BT_ENABLED) || !defined(CONFIG_BLUEDROID_ENABLED)
#error Bluetooth is not enabled! Please run `make menuconfig` to and enable it
#endif
#if !defined(CONFIG_BT_SPP_ENABLED)
#error Serial Port Profile for Bluetooth is not available or not enabled. It is only available for the ESP32 chip.
#endif
BluetoothSerial SerialBT;

#define ledV 16
#define ledR 15

#include <ESP32Servo.h>
Servo Delantero;
Servo Medio;
Servo Trasero;

void setup(){

  Serial.begin(115200);
  SerialBT.begin(device_name);
  Serial.printf("The device with name \"%s\" is started.\nNow you can pair it with Bluetooth!\n", device_name.c_str());
  pinMode (ledV, OUTPUT);
  pinMode (ledR, OUTPUT);
  Delantero.attach(13);
  Medio.attach(12);
  Trasero.attach(14);
}

void espera(){
  digitalWrite (ledR, HIGH);
  digitalWrite (ledV, LOW);
  Delantero.write(90); delay(100);
  Medio.write(90); delay(100);
  Trasero.write(90);delay(1000); 
}
void avanzar(){
  digitalWrite (ledV, HIGH);
  digitalWrite (ledR, LOW);
  Medio.write(120); delay(150);
  Delantero.write(135); delay(150);
  Trasero.write(135); delay(150);
  Medio.write(90); delay(150);
  Delantero.write(90); delay(150);
  Trasero.write(90); delay(150);
  Medio.write(60); delay(150);
  Delantero.write(45); delay(150);
  Trasero.write(45); delay(150);
  Medio.write(90); delay(150);
  Delantero.write(90); delay(150);
  Trasero.write(90); delay(150);
}
void loop() {
 
 espera();
char dato = SerialBT.read();
switch (dato){
  case 'v':
    avanzar();
    break;
  
  case 'r':
  espera();
  break;
}
}
if (SerialBT.available()) {
  char dato = SerialBT.read(); 
}

Lee las Normas del foro y edita el título inútil, también edita el post y adjunta el código como corresponde (debe verse como el de arriba).

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.