I´m having trouble making conditionals with various conditions, I have port 9, 8, 7, 6, 5 as outputs, as you can see in the code, when 8, 7, 6 or 5 are high, port 9 is also high, however I need to make that when ports 8,7,6 and 5 are low (when they are ALL low), 9 is also low, in order to do that I stated this conditional:
while ((8==LOW) and (7==LOW) and (6==LOW) and (5==LOW)) {
digitalWrite(9, LOW);
}
but it is not working and I cant find the mistake
Here is my code
int state = 'r';
void setup() {
Serial.begin(9600);
pinMode(9, OUTPUT);
pinMode(8, OUTPUT);
pinMode(7, OUTPUT);
pinMode(6, OUTPUT);
pinMode(5, OUTPUT);
}
void loop() {
if(Serial.available()>0){
state = Serial.read();
}
if(state=='a'){
digitalWrite(8 ,HIGH);
digitalWrite(9 ,HIGH);
}
if(state=='b'){
digitalWrite(8 ,LOW);
}
if(state=='c'){
digitalWrite(7,HIGH);
digitalWrite(9,HIGH);
}
if(state=='d'){
digitalWrite(7,LOW);
}
if(state=='e'){
digitalWrite(6,HIGH);
digitalWrite(9,HIGH);
}
if (state =='f'){
digitalWrite(6, LOW);
}
if(state=='g'){
digitalWrite(5,HIGH);
digitalWrite(9,HIGH);
}
if(state=='h'){
digitalWrite(5,LOW);
}
if(state=='q'){
digitalWrite(9,HIGH);
digitalWrite(8,HIGH);
digitalWrite(7,HIGH);
digitalWrite(6,HIGH);
digitalWrite(5,HIGH);
}
if(state=='r'){
digitalWrite(9,LOW);
digitalWrite(8,LOW);
digitalWrite(7,LOW);
digitalWrite(6,LOW);
digitalWrite(5,LOW);
}
while ((8==LOW) and (7==LOW) and (6==LOW) and (5==LOW)) {
digitalWrite(9, LOW);
}
}