Hi to all,
Just i tried to complete some part, but i am stuck at some place , let me know if anyone can solve this problem.
In this program if i want off all LED at the same time when P1 and L2 both are HIGH(on).
I've tried to use boolean AND operator,if, do while, while
Still it's not working ..Let me know if there is any logical error
my code is,
const int P1 = 2; // the number of the pushbutton pin
const int P2 = 3; // the number of the pushbutton pin
const int L1 = 4; // the number of the pushbutton pin
const int L2 = 5; // the number of the pushbutton pin
int S1 = 8; // the number of the LED pin
int S2 = 9; // the number of the LED pin
int S3 = 10; // the number of the LED pin
int S4 = 11; // the number of the LED pin
// variables will change:
int P1State = 0; // variable for reading the pushbutton status
int P2State = 0; // variable for reading the pushbutton status
int L1State = 0; // variable for reading the pushbutton status
int L2State = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(S1, OUTPUT);
pinMode(S2, OUTPUT);
pinMode(S3, OUTPUT);
pinMode(S4, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(P1, INPUT);
pinMode(P2, INPUT);
pinMode(L1, INPUT);
pinMode(L2, INPUT);
}
void loop(){
// FOR P1 ACTIVE
P1State = digitalRead(P1);
P2State = digitalRead(P2);
L1State = digitalRead(L1);
L2State = digitalRead(L2);
if (P1State == HIGH)
{
// turn LED on:
digitalWrite(S1, HIGH);
digitalWrite(S3, HIGH);
digitalWrite(S2, LOW);
digitalWrite(S4, LOW);
}
if (L2State == HIGH)
{
digitalWrite(S1, LOW);
digitalWrite(S3, LOW);
digitalWrite(S2, HIGH);
digitalWrite(S4, HIGH);
}
if (L1State ==HIGH)
{
digitalWrite(S1, LOW);
digitalWrite(S3, LOW);
digitalWrite(S2, LOW);
digitalWrite(S4, LOW);
}
if (L2State ==HIGH && P1State==HIGH)
{
digitalWrite(S1, LOW);
digitalWrite(S3, LOW);
}
}