two push button and three led

This program for two push button(momentary) controlled three LED using Arduino UNO.

as per below mentioned programe.when i press 'pinButton' LED and LED2 get ON at a time.When i press 'pinButton1' LED1 and LED2 get ON at a time.

I want LED2 in HIGH state in for 1 second than after LED & LED1 get HIGH state.

please help me to build a program

int pinButton = 8; //the pin where we connect the button
int pinButton1 = 9;
int LED = 2; //the pin we connect the LED
int LED1=3;
int LED2=4;
void setup() {
  pinMode(pinButton, INPUT); //set the button pin as INPUT
  pinMode(LED, OUTPUT); //set the LED pin as OUTPUT
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
}

void loop() {
  int stateButton = digitalRead(pinButton); //read the state of the button
  int stateButton1 = digitalRead(pinButton1);
  if(stateButton == 1) { 
     digitalWrite(LED2, HIGH);
     
     digitalWrite(LED, HIGH); 
     digitalWrite(LED1, LOW);
} else if (stateButton1 == 1){
     digitalWrite(LED2, HIGH);
     digitalWrite(LED, LOW);
     digitalWrite(LED1, HIGH);
}
  else{
    digitalWrite(LED2, LOW);
}
}

Where are you stuck? What did you try?

For timing, Blink without delay is a good start. Also note, a button becoming pressed (happens once every press) isn't the same as a button that is pressed (happens many many times a second when read by a micro controller)

Also, do you also count like that in real life? Dollar, one dollar, two dollar... At least number all or use arrays which is always better instead of suffixing variable names.

author=septillion link=msg=3851022 date=1535131737]
Where are you stuck? What did you try?

I want, first LED2 get ON for 1second after that other led's will ON with respective push button

Once i tried with delay() but not get succes.

digitalWrite(LED2, HIGH);
    delay(1000);
    digitalWrite(LED, HIGH); 
    digitalWrite(LED1, LOW);
} else if (stateButton1 == 1){
    digitalWrite(LED2, HIGH);
  delay(1000);
    digitalWrite(LED, LOW);
    digitalWrite(LED1, HIGH);

when i use delay() all function get delayed.

That's correct. Did you read the rest of my post? And more specific, did you read what I told you to (part about timing)? :wink:

Your explanaition is pretty poor, so it is hard to give good advice. But it sounds like you want to make a "state machine" in which button events starts non-blocking sequences of events OR you need a helper library which can do it for you.

septillion:
.. At least number all or use arrays which is always better instead of suffixing variable names.

now iam nubered the push button is that Button1&Button2 and LED is that LED0,LED1 &LED3

int Button1 = 8; //the pin where we connect the button
int Button2 = 9;
int LED0 = 2; //the pin we connect the LED
int LED1=3;
int LED2=4;
void setup() {
  pinMode(Button1, INPUT); //set the button pin as INPUT
  pinMode(Button2, INPUT);
  pinMode(LED0, OUTPUT); //set the LED pin as OUTPUT
  pinMode(LED1, OUTPUT);
  pinMode(LED2, OUTPUT);
}

void loop() {
  int stateButton = digitalRead(Button1); //read the state of the button
  int stateButton1 = digitalRead(Button2);
  if(stateButton == 1) { 
     digitalWrite(LED2, HIGH);
     
     digitalWrite(LED0, HIGH); 
     digitalWrite(LED1, LOW);
} else if (stateButton1 == 1){
     digitalWrite(LED2, HIGH);
     digitalWrite(LED0, LOW);
     digitalWrite(LED1, HIGH);
}
  else{
    digitalWrite(LED2, LOW);
}
}

please ....help

sreekanthmp:
now iam nubered the push button is that Button1&Button2 and LED is that LED0,LED1 &LED3

What?! Do you always count like 0, 1, 3? I would count like 0, 1, 2 (as a programmer) or 1, 2, 3 in daily life...

But:

septillion:
Did you read the rest of my post? And more specific, did you read what I told you to (part about timing)?[/b]
[/quote]
aka:
> septillion:
> For timing, Blink without delay is a good start.
Google it, READ it!