quiero salir de bucle while cuando se precione el boton menu.
[#include <SoftwareSerial.h>
#include <Nextion.h>
SoftwareSerial nextion(10, 11);// Nextion TX to pin 2 and RX to pin 3 of Arduino
Nextion myNextion(nextion, 9600); //create a Nextion object named myNextion using the nextion serial port @ 9600bps
#include <PID_v1.h>
#include <OneWire.h>
#include <DallasTemperature.h>
#define pinData 2 // Pin donde se conectará el pin de datos.
#define SSR 6
#define led 13
#define tiempoCiclo 1000
double Setpoint, Input, Output; // Define Variables
double Kp=10, Ki=4, Kd=1200; // Especifica parametros iniciales
float temperatura=0;
unsigned long respuestaUltimaTemperatura = 0;
unsigned long lastPIDCalculation = 0;
float prevTemperature = -9999.0;
boolean button1State ;
boolean button2State ;
float cuenta = 335;
PID myPID(&Input, &Output, &Setpoint, Kp, Ki, Kd, DIRECT);
OneWire ourWire(pinData); // Pin como bus para la comunicación OneWire
DallasTemperature sensors(&ourWire); //Se instancia la librería DallasTemperature
const int ledPin = 6; //Puerto con salida PWM
// Variables
int cicloTrabajo =50; //Variable para el ciclo de trabajo del led
boolean button3State ;
boolean button4State ;
void setup() {
myNextion.init();
pinMode(ledPin, OUTPUT);
Serial.begin(9600);
Setpoint = 0; // initialize the variables we're linked to
myPID.SetOutputLimits(0, tiempoCiclo);
myPID.SetSampleTime(tiempoCiclo);
myPID.SetMode(AUTOMATIC);
Serial.begin(9600); // Aranca comunicacion serie
pinMode(SSR, OUTPUT);
pinMode(4,OUTPUT);
digitalWrite(4, LOW);
digitalWrite(SSR, LOW);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
sensors.begin();
}
void loop() {
String message = myNextion.listen(); //check for message
while(message == "65 1 2 0 ffff ffff ffff" ){manual();}
while(message == "65 1 1 0 ffff ffff ffff" ){servo();}
Serial.println(message);
}
void manual() {
String message = myNextion.listen(); //check for message
if (message == "65 3 5 0 ffff ffff ffff") {
button3State = HIGH;
}
else{button3State = LOW;}
if (message == "65 3 3 0 ffff ffff ffff") {
button4State = HIGH;
}
else{button4State = LOW;}
if (cicloTrabajo == 50) { myNextion.setComponentText("manual", String("25")); }
if (cicloTrabajo == 100) { myNextion.setComponentText("manual", String("50")); }
if (cicloTrabajo == 150) { myNextion.setComponentText("manual", String("75")); }
if (cicloTrabajo >= 200) { myNextion.setComponentText("manual", String("100"));}
if (cicloTrabajo <= 0) { myNextion.setComponentText("manual", String("0"));}
if ( button3State == HIGH && cicloTrabajo <=200){
cicloTrabajo +=50;
}
if (button4State == HIGH && cicloTrabajo >=50){
cicloTrabajo -=50;
}
analogWrite(ledPin, cicloTrabajo);
delay(300);
}
void servo() {
delay(200);
botones();
if(button1State == HIGH){cuenta--; }
if(button2State == HIGH){cuenta++; }
if(button2State == HIGH){button1State = LOW;}
if(button1State == HIGH){button2State = LOW;}
if(cuenta <=300){cuenta = 300;}
if(cuenta >=375){cuenta = 375;}
if(temperatura >= 37.5){
digitalWrite(4, HIGH);
delay(100);
digitalWrite(4, LOW);
delay(100);
}
else {digitalWrite(4, LOW);}
if(temperatura <= 10){
digitalWrite(4, HIGH);
delay(100);
digitalWrite(4, LOW);
delay(100);
digitalWrite(SSR, LOW);
}
Serial.println(button1State);
Serial.println(button2State);
Serial.println(Setpoint);
Setpoint = cuenta/10;
myNextion.setComponentText ("setpoint", String (Setpoint, 1));
myNextion.setComponentText ("temperatura", String (temperatura, 1));
if (millis() - respuestaUltimaTemperatura >= tiempoCiclo) {
temperatura = sensors.getTempCByIndex(0);
Input = (double)temperatura;
myPID.Compute();
lastPIDCalculation = millis();
Serial.print(temperatura);
Serial.print(" , ");
Serial.println(Output/50);
sensors.requestTemperatures();
respuestaUltimaTemperatura = millis();
}
control();
}
void control() {
if ((millis() <= (lastPIDCalculation + Output)) || (Output == tiempoCiclo)) {
// Power on:
digitalWrite(SSR, HIGH);
digitalWrite(led, HIGH);
} else {
// Power off:
digitalWrite(SSR, LOW);
digitalWrite(led, LOW);
}
// delay(10);
}
void botones() {
String message = myNextion.listen(); //check for message
if (message == "65 2 6 0 ffff ffff ffff") {
button1State = HIGH;
}
else{button1State = LOW;}
if (message == "65 2 7 0 ffff ffff ffff") {
button2State = HIGH;
}
else{button2State = LOW;}
}
]
espero puedan ayudarme , cualquier sugerencia sera buena.