I want When,
light=0, ir=0 then output will pin 8 high & pin 12 low.
light=0, ir=1 then output will pin 8 high & pin 12 high.
light=1, ir=0 then output will pin 8 low & pin 12 low.
light=1, ir=1 then output will pin 8 low & pin 12 low (This statement does not work).
Please find the code & suggest me, if any modification is needed.
void setup() {
pinMode(8,OUTPUT); //logic output.
pinMode(12,OUTPUT); //logic output.
pinMode(2, INPUT); //value input.
pinMode(4, INPUT); //value input.
Serial.begin(9600);
}
void loop() {
int light = digitalRead(2); //value input.
int ir = digitalRead(4); //value input.
if (light == LOW && ir == LOW)
{
digitalWrite(8, HIGH);
digitalWrite(12, LOW);
delay(2000);
}
if (light == LOW && ir == HIGH)
{
digitalWrite(8, HIGH);
digitalWrite(12, HIGH);
delay(2000);
}
if (light == HIGH && ir == LOW)
{
digitalWrite(8, LOW);
digitalWrite(12, LOW);
delay(2000);
}
if (light == HIGH && ir == HIGH) //This condition does not work.
{
digitalWrite(8, LOW);
digitalWrite(12, LOW);
delay(2000);
}
digitalWrite(8, LOW);
digitalWrite(12, LOW);
delay(2000);
}
if (light == HIGH) { digitalWrite(8,LOW); digitalWrite(12,LOW); delay (2000); }. Or maybe that isn't what you intended and that's where the error in your code is. – StarCat Jan 25 '20 at 09:40delay(2000);after all of theifstatements – jsotola Jan 25 '20 at 16:10