2 buttons as yes and no

hey guys, I need to use 2 buttons on my project one for yes and one for no, it asks the user several question, like do you want meat in your meal? then you can press yes and it does the function, you can press the yes button for 3 times and then it proceeds to the next question automatically instead of pressing no, thanks in advance guys!!!!!!!!!!!!!

NSSMV: hey guys, I need to use 2 buttons on my project one for yes and one for no, it asks the user several question, like do you want meat in your meal? then you can press yes and it does the function, you can press the yes button for 3 times and then it proceeds to the next question automatically instead of pressing no, thanks in advance guys!!!!!!!!!!!!!

Permission granted. Proceed.

Do you need some help with such a simple task as reading the state of a pin that a switch (NOT a button) is connected to?

I really dont know how, I dont know how to save the state of a short press, with the two buttons, I would really appreciate if youll help me

Did you have a look at some of the examples that come with the IDE? Button, Debounce and StateChangeDetection; start with the first one that shows you how to save the state of the button to a variable.

To determine if a button is pressed long or short, you can use a 'timer'. Record that start time (millis()) when the button was pressed; when the button is released you compare the start time with the current time (millis()). Take into account that buttons can bounce.

I tried but i didn't succeed i would really appreciate if you'll help me with that

NSSMV: I tried but i didn't succeed i would really appreciate if you'll help me with that

Let's see what you tried and describe the problems that you had.

UKHeliBob: Let's see what you tried and describe the problems that you had.

I tried a lot of programs from the internet (modified them a bit because they only have one button but nothing really worked

How did you sew your buttons onto the Arduino?

You're not taking the hint. If you post a program that you have actually modified and tested and then explain what it does wrong we can probably help you to get it working. But we're not going to do ALL the work for you.

Steve

"I tried a lot of programs from the internet" - SIGH.. You really cannot expect ppl in the forum to spend time on creating something you are reluctant to do your self. Instead of spending your own and other ppl's time on repeating your question you should get on studying how to achieve your goal:

https://www.arduino.cc/en/Guide/HomePage

slipstick: You're not taking the hint. If you post a program that you have actually modified and tested and then explain what it does wrong we can probably help you to get it working. But we're not going to do ALL the work for you.

Steve

int buttonPin = 2; int buttonpin2 = 3; n

int buttonState = 0; int buttonState1 = 0; boolean b1 = false; boolean b2= false; void setup() {

pinMode(buttonPin, INPUT_PULLUP); pinMode(buttonpin2, INPUT_PULLUP); Serial.begin(9600); }

void loop() {

Serial.print ("do you want meat");

while(0==0) { if (buttonState == HIGH) {

if ( b1 == 0){

b1=1; } } break; if (buttonState2 == HIGH) {

if ( b2 == 0){ b2=1; }

} break; } if(b1==true) { Serial.print("meat"); }

b1= false; b2 = false;

}

Im a beginner (as you can see) thats just a really small part of the entire program(UI) if you have any suggestion or ideas on how to do it im all ears

Try again when you have something that compiles and that you have tested (and please post it in </>code tags). Then tell use what it does and what you want it to do.

Hint: the 2nd line doesn’t need the n after the semicolon and you need to sort out your variable names…is the second one going to be called something1 or something2?

Steve

Please edit your reply #10 and add code tags.

Type 
[code]before your code and [/code]
 after your code.

Makes it easier to read and copy.

#include <Button.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
Button button1 = Button(8, PULLDOWN);
Button button2 = Button(9, PULLDOWN);
int firstRun = 0;
int b1 = 0;
int b2 = 0;

void setup() {
lcd.begin(16, 2);
}

void loop() {
 buttonState();
 if(firstRun == 0) {             // Where are we?
   firstRun = 1;
   lcd.setCursor(0,0);
   lcd.print("Q1");            // Print Question
   lcd.setCursor(0,1);
   lcd.print("Yes or No above");
 }
 if(b1 == 1) {                // if yes is pressed, print Q2
     if(firstRun == 1) {
       question();
       lcd.print("Q2");
       firstRun = 2;
     }
  }
  if(b1 == 1) {
       if(firstRun == 2) { // if yes is pressed again, print A1
         lcd.clear();
       lcd.print("A1");
       delay(3000);      // wait for a bit
         lcd.clear();
         firstRun = 0;     // got back to the beggining
       }
   } 
   if(b2 == 1) {        // if no is pressed, print A2
        if(firstRun == 2) { 
         lcd.clear();
       lcd.print("A2");
       delay(3000);
         lcd.clear();
         firstRun = 0;
       }
   } 
   if(b2 == 1) {           // if no is pressed , print Q3
     if(firstRun == 1) {
       question();
       lcd.print("Q3");
       firstRun = 3;
     }
   }
   if(b1 == 1) {
          if(firstRun == 3) { 
             lcd.clear();
           lcd.print("A3");
           delay(3000);
             lcd.clear();
             firstRun = 0;
         }
    }
    if(b2 == 1) {
           if(firstRun == 3) { 
             lcd.clear();
           lcd.print("A4");
           delay(3000);
             lcd.clear();
             firstRun = 0;
           }
    }    
 }

 
void buttonState() {
  delay(100);
  b1 = button1.isPressed();
  b2 = button2.isPressed();
}
   
void question() {
     lcd.clear();
     lcd.setCursor(3,1);
     lcd.print("Y or N");
     lcd.setCursor(0,0);
     delay(500);
     buttonState();
}
  
/*      
void loop() {  /////////////////////////////////////DEBUG/////////////////////////////////////
 buttonState();
 lcd.setCursor(0,0);
 lcd.print(b1);
 lcd.setCursor(0,1); 
 lcd.print(b2);
}              /////////////////////////////////////DEBUG////////////////////////////////////
*/

MonkeyJam did a similar code to mine, should i use pulldown like he did?