Menu with pushbutton Arduino (esp32)

Asked

Viewed 42 times

0

I have a question about building a menu with buttons. Initially, I have to wait for a button to be pressed. When someone leaves, I have to open the button option pressed. I tried the following, but I was unsuccessful. Anyone have any suggestions?

void loop()
{
    int button1 = digitalRead(but1);
    int button2 = digitalRead(but2);

    while(button1 == LOW && button2 ==LOW){};
    while(button1 == HIGH || button2 ==HIGH){
        if(button1 == HIGH){
            Serial.print("RFID")
            rfid_menu();
        }

        if(button2 == HIGH){
            Serial.print("FingerPrint")
            fingerprint_menu();
        }
    };
}

1 answer

0


It seems to me it’s just a logical error in the code.

void loop()
{
    int button1 = digitalRead(but1);
    int button2 = digitalRead(but2);

    // esse while esta travando seu programa
    // por que só realiza a leitura dos botão uma vez e utiliza ela para sempre 
    // se nenhum estiver apertado.
    while(button1 == LOW && button2 ==LOW){}; 

    // na verdade ocorre com esse while a mesma coisa, mas se existir algum 
    // botão apertado na primeira execução do loop
    while(button1 == HIGH || button2 ==HIGH){
        if(button1 == HIGH){
            Serial.print("RFID")
            rfid_menu();
        }

        if(button2 == HIGH){
            Serial.print("FingerPrint")
            fingerprint_menu();
        }
    };
}

So if you take them both out while your program should work as expected, only with the if

Browser other questions tagged

You are not signed in. Login or sign up in order to post.