Stuck in the middle: A decision, two push buttons

Hello, fellas.
I need your help. I started a project in the company but despite my will of learning, I can go further in the project.
Part of the project consists of receive data from serial, read, show to the user through LCD and this one makes a decision pushing a button(yes/no).
When yes push button is pressed, he locks his work and cannot receive any data from serial until finish (when pressing a button). However, when pressed the NO button, everything starts again, in the loop.

(sorry but my natural language is not English)

Here follow the code:

#include <LiquidCrystal_I2C.h>

LiquidCrystal_I2C lcd (0x27, 16, 2);

int pushButtonSim = 4;
int pushButtonNao = 5;

int pushButtonSimState = 0;
int pushButtonNaoState = 0;

int lastPushButtonSimState = LOW;
int lastPushButtonNaoState = LOW;

unsigned long lastDebounceTimePushButtonSim = 0;
unsigned long lastDebounceTimePushButtonNao = 0;

unsigned long debounceDelay = 50;

void setup() {
 pinMode(pushButtonSim, INPUT);
 pinMode(pushButtonNao, INPUT);

 Serial.begin(9600);

 lcd.begin();
 lcd.clear();
 lcd.setCursor(0, 0);
 lcd.print("Aguardando");
 lcd.setCursor(0, 1);
 lcd.print("ordem...");
}

void loop() {
 if (Serial.available() > 0) {
   // Lê toda string recebida
   lcd.clear();
   String teste1 = leStringSerial();
   int i;
   String id = "";
   for (i = 1; i < 3; i++) {
     id += teste1[i];
   }
   String origem = "";
   for (i = 4; i < 7; i++) {
     origem += teste1[i];
   }
   String destino = "";
   for (i = 8; i < 11; i++) {
     destino += teste1[i];
   }
   String idOperacao = "";
   for (i = 12; i < 15; i++) {
     idOperacao += teste1[i];
   }

       lcd.setCursor(0, 0); lcd.print("Orig: "); lcd.setCursor(6, 0); lcd.print(origem); lcd.setCursor(13, 0); lcd.print("SIM");
   lcd.setCursor(0, 1); lcd.print("Dest: "); lcd.setCursor(6, 1); lcd.print(destino); lcd.setCursor(13, 1); lcd.print("NAO");
   delay(2000);

   int readingSim = digitalRead(pushButtonSim);
   int readingNao = digitalRead(pushButtonNao);
   
   if (readingNao != lastPushButtonNaoState) {
     lastDebounceTimePushButtonNao = millis();
   }

   delay(500);

   if ((millis() - lastDebounceTimePushButtonNao) > debounceDelay) {
     if (readingNao != pushButtonNaoState) {
       pushButtonNaoState = readingNao;
       lcd.clear();
       lcd.print(pushButtonNaoState);
       lcd.print(" 1");
       delay(5000);
       if (pushButtonNaoState == HIGH) {
         lcd.clear();
         //#;id da empilhadeira; origem; destino; id da operação; estado igual a zero, que significa que não foi aceito a ordem
         Serial.print("#"); Serial.print(id); Serial.print(";"); Serial.print(origem); Serial.print(";"); Serial.print(destino); Serial.print(";"); Serial.print(idOperacao); Serial.print(";"); Serial.println("0");
         lcd.print(pushButtonNaoState);
         lcd.print(" 2");
         delay(5000);
         teste1 = leStringSerial();

       }
     }
   }
   lastPushButtonNaoState = readingNao;

   
     if (readingSim != lastPushButtonSimState) {
     lastDebounceTimePushButtonSim = millis();
     }
     if ((millis() - lastDebounceTimePushButtonSim) > debounceDelay) {
     if (readingSim != pushButtonSimState) {
       pushButtonSimState = readingSim;
       if (pushButtonSimState == HIGH) {//se atidade for aceita
         String estado = "1";
         lcd.clear();
         lcd.setCursor(0, 0); lcd.print("Orig: "); lcd.setCursor(6, 0); lcd.print(origem); 
         lcd.setCursor(13, 0); lcd.print("SIM");
         lcd.setCursor(0, 1); lcd.print("Dest: "); lcd.setCursor(6, 1); lcd.print(destino); 
         lcd.setCursor(13, 1); lcd.print("NAO");
         Serial.print("#"); Serial.print(id); Serial.print(";"); Serial.print(origem); Serial.print(";"); 
         Serial.print(destino); Serial.print(";"); Serial.print(idOperacao);
         Serial.print(";"); Serial.println(estado);
         if (estado == "1") { //aguarda a comunicação de conclusão da tarefa
           lcd.setCursor(0, 0); lcd.print("Orig: "); lcd.setCursor(6, 0); lcd.print(origem); lcd.setCursor(13, 0); lcd.print("SIM");
           lcd.setCursor(0, 1); lcd.print("Dest: "); lcd.setCursor(6, 1); lcd.print(destino); lcd.setCursor(13, 1); lcd.print("NAO");
           if (pushButtonSimState == HIGH) { //se atidade for concluida
             lcd.clear();
             Serial.print("#"); Serial.print(id); Serial.print(";"); Serial.print(origem); Serial.print(";"); Serial.print(destino); Serial.print(";"); Serial.print(idOperacao); Serial.print(";"); Serial.println("Concluido");
             teste1 = leStringSerial();
           }
           if (pushButtonNaoState == HIGH) {
             lcd.clear();
             Serial.print("#"); Serial.print(id); Serial.print(";"); Serial.print(origem); Serial.print(";"); Serial.print(destino); Serial.print(";"); Serial.print(idOperacao); Serial.print(";"); Serial.println("0");
             teste1 = leStringSerial();
           }

       }
     }
    }
 }
}
String leStringSerial() {
 String conteudo = "";
 char caractere;

 while (Serial.available() > 0) {
   caractere = Serial.read();
   if (caractere != '\n') {
     conteudo.concat(caractere);
   }
   delay(10);
 }

 return conteudo;

}

Please edit your post and add code [/] tags, to make it all readable.

The code button is the one that looks like </>  and it makes your code looks like this and makes it easy to copy to a text editor. See How to use the Forum

Your code is too long for me to study quickly without copying to a text editor.

...R

Ok, edit it.
The most important thing in the code is how I ask to the user and wait for response... how I keep in the if statement until answer.

There is a simple example of user input in Planning and Implementing a Program. That tutorial also shows ho code is much easier to manage if you break it up into small single-purpose functions.

...R

Thanks, guys.
After sit down and think for a while I could answer all my question.

I needed to use while statements and some boolean variables.

See ya