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);}
//}//