NEED CODE FOR MY SIMPLE LOGIC

I am in need of a Code for my simple Logic using 2 Buttons and Two Out puts with Delay, i am stuck in programming code…Kindly Help me.

Using:
.2 Digital Buttons as Input.
.2 LEDs as Output.

LOGIC:

WHEN

.INPUT A ON(button pressed) Then Output A Turns ON for 1 second then turns OFF
.INPUT B ON(button pressed) Then Output B Turns ON for 5 seconds then turns OFF

but IF INPUT A and INPUT B turns ON together(buttons pressed) Then NO OUTPUT.

Kindl Help me with this Code i am new to Programming.
Photos Attached

I am in need of a Code for my simple Logic using 2 Buttons and Two Out puts with Delay, i am stuck in programming code…Kindly Help me.

Using:
.2 Digital Buttons as Input.
.2 LEDs as Output.

LOGIC:

WHEN

.INPUT A ON(button pressed) Then Output A Turns ON for 1 second then turns OFF
.INPUT B ON(button pressed) Then Output B Turns ON for 5 seconds then turns OFF

but IF INPUT A and INPUT B turns ON together(buttons pressed) Then NO OUTPUT.

Kindl Help me with this Code i am new to Programming.
Photos Attached

CODE:

const int buttonPin = 10; // the number of the pushbutton pin 2
const int ledPin = 5; // the number of the LED pin
const int buttonPin1 = 9; // the number of the pushbutton pin 3
const int ledPin1 = 6; // the number of the LED pin2
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
int buttonState1 = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(buttonPin, INPUT);
pinMode(buttonPin1, INPUT);
}

void loop() {

buttonState = digitalRead(buttonPin);
buttonState1 = digitalRead(buttonPin1);

if (buttonState == HIGH) {
digitalWrite(ledPin,HIGH);
delay (1000);
}
else {
// turn LED off:
digitalWrite(ledPin1, LOW);
}

// check if the pushbutton1 is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 ==HIGH) {
// turn LED on:
digitalWrite(ledPin1, HIGH);
delay (1000);

}
else {
// turn LED off:
digitalWrite(ledPin1, LOW);

}

}
// if (buttonState = HIGH)
// (buttonState1 = HIGH)
// {
// rurn LED OFF:
// digitalWrite (ledPin1,LOW);
// digitalWrite (ledPin,LOW);
// }
// else {
// digitalWrite(ledPin, LOW);
// digitalWrite(ledPin1, LOW);}
//}//

  1. Why do you scream?
  2. Why do you cross post / repost?
  3. Why didn't you read the simple How to use this forum? Otherwise you would have used code tags.

(deleted)

The first thing you need to check is whether both buttons are pressed. There is no point checking the individual buttons if both are pressed.

...R

@uzairbhaijaan, please do not cross-post. Threads merged.

uzairbhaijaan:
I am in need of a Code for my simple Logic using 2 Buttons and Two Out puts with Delay, i am stuck in programming code..Kindly Help me.

LOGIC:

WHEN

.INPUT A ON(button pressed) Then Output A Turns ON for 1 second then turns OFF
.INPUT B ON(button pressed) Then Output B Turns ON for 5 seconds then turns OFF

but IF INPUT A and INPUT B turns ON together(buttons pressed) Then NO OUTPUT.

The description sounds WEIRD to me.
You probably never want to use any delay().

Perhaps I try a different description of the logic:

If button A is pressed, start output sequence A (one second on then off for output A)
If button B is pressed, start output sequence B (five seconds on then off for outputB)

But in case buttton A is pressed while output sequence B is in progress, stop any output sequence and set outputs to off
And in case button B is pressed while output sequence A is in progress, stop any output sequence and set outputs to off.

Be aware: You never can press two buttons at exactly the same mcrosecond, even if you try: One button will be first, the other button will be second. Even if the time difference is less than one millisecond.

So if you try to press both buttons at the same time, the first button starts its sequence

Let's say button A is 0.01 ms (10µs) pressed before button B is pressed.

Then this could happen:
button A starts output sequence A.
Then after 10 microseconds or sp, button B is pressed, output sequence A is cancelled and every output goes off.

Sequence A will only finish if button B is NOT pressed while sequence A is in progress.

And sequence B will only finish if button A is NOT pressed while sequence B is in progress.

Is that what you want?

jurs:
So if you try to press both buttons at the same time, the first button starts its sequence

I had assumed the OP wishes to check if both buttons are pressed before the sequence starts - hence my suggestion in Reply #4 to check the BOTH conditon first.

I guess it would be a good idea to have a short interval (perhaps 100 millisecs) between pressing the first button and checking for BOTH buttons to allow time for the second button to be pressed.

...R

Hi,
Welcome to the forum.

Please read the first post in any forum entitled how to use this forum.
http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code.
It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom... :slight_smile: