push buttonsss

int b1 = 9;
int b2 = 8;
int 


//button status
boolean bu1 =0;
boolean bu2 =0;

//Status of whether or not a button has been pressed
int hold = 0;


void setup() {                
  //allows you to see on a computer who buzzed in first
  Serial.begin(9600);
 //Lockout Status LED pin with is statndard on the Arduino Board(s)
  pinMode(13, OUTPUT);
  //Button inputs defined
  pinMode(b1, INPUT);
  pinMode(b2, INPUT);

  
  //The delay allows time for the voltage to stabilize (exp. because the electronics are not removed from the buttons!)
  delay(1000);
}

void loop() {
  
  //Read to see if a button is pushed
  if(hold == 0){
    bu1 = digitalRead(b1);
    bu2 = digitalRead(b2);
    
    //player 1
    if(digitalRead(b1)==HIGH||digitalRead(b2)==LOW)
   {
      hold=1; //lockout the other users
      Serial.println("Player 1");
    }
    //player 2
    if(digitalRead(b2)==HIGH||digitalRead(b1)==LOW){
     
      hold=1; //lockout the other users
      Serial.println("Player 2");

    }
  }
  else{
    digitalWrite(13, HIGH);   // set the LED on to indicate that the other users are locked out
  }
}


void time(){
 
 delay(15000); 
}
[font=Verdana][/font]

Sir i need a little help..i am a beginner here,,i dont think this gonna work..:smiley: please help for better code..

i want to output the first button who pressed first. thanks

,i dont think this gonna work.

Not a great attitude to approach software development.

Make sure both switches are on the same port and read the whole port.
digitalRead is relatively slow.

,i dont think this gonna work.

You give up without even trying ? Make some experiments with your code, post your results and then ask questions. :slight_smile:

const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;     // the number of the LED pin



// variables will change:
int buttonState = 0;         // variable for reading the pushbutton status
int hold=0;

void setup() {
  
// initialize the LED pin as an output:

  pinMode(ledPin, OUTPUT);      

  // initialize the pushbutton pin as an input:

  pinMode(buttonPin, INPUT);     
}

void loop(){

  // read the state of the pushbutton value:

  buttonState = digitalRead(buttonPin);


  // check if the pushbutton is pressed.

  // if it is, the buttonState is HIGH:
if(hold==0)
{

if(buttonState1||buttonState2){
delay(5000);

{
  if (buttonState == HIGH) {  
    // turn LED on:    
	hold=1;
	digitalWrite(ledPin1, HIGH);  
  } 
if(buttonState2==HIGH){
	hold=1;
	digitalWrite(ledPin2, HIGH);
  else {
    // turn LED off:
    digitalWrite(ledPin, LOW); 
  }
}
{

well thanks sir..i have sought a new code..i just need it yout reply...

yinyangXD:

const int buttonPin = 2;     // the number of the pushbutton pin

const int ledPin =  13;     // the number of the LED pin




How can you check which person pressed their button first with only a single button



> // check if the pushbutton is pressed.


How?



if(buttonState1||buttonState2){
delay(5000);

{
  if (buttonState == HIGH) {



You're checking three different buttonState variables, but you've only declared and read 1; That's not going to work.

The last code you posted doesn't even compile. Please take at least the effort to post compilable code. Thank you.

AWOL:
digitalRead is relatively slow.

Not compared to me it isn't.

Not compared to me it isn’t.

It’s all about perspective.