time delay not working

Hi,

I am trying to toggle a relay switch on when reading a LOW from an encoder, staying on for 3 seconds and then turning the switch off and repeat that cycle. When reading a HIGH from the encoder the switch should stay off. The code behaves as expected (turns the switch on when reading LOW and turning it off when reading a HIGH) but is bypassing the time delay of 3 seconds. I am suspecting a poorly placed line but haven’t been able to place it correctly. Would appreciate your help. Thanks!

<int Switch = 2;
int ENCD1 = 7;

void setup() {
Serial.begin(9600);
pinMode(Switch, OUTPUT);
pinMode(ENCD1, INPUT);

}

void loop() {
if(digitalRead(ENCD1) == HIGH)
{
digitalWrite(Switch, LOW);
}
else if(digitalRead(ENCD1) == LOW)
{
{
digitalWrite(Switch, HIGH);
delay(3000);
}
}
}>

Please read the sticky post at the top of this forum about how to properly post your code using code tags. It helps people help you.

Your delay() function is not getting skipped. It is functioning, but you are not turning the switch off after is has executed.

int Switch = 2;
int ENCD1 = 7;

void setup() {
  Serial.begin(9600);
  pinMode(Switch, OUTPUT);
  pinMode(ENCD1, INPUT);
}

void loop() {
  if (digitalRead(ENCD1) == HIGH)
  {
    digitalWrite(Switch, LOW);
  }
  else  if (digitalRead(ENCD1) == LOW)
  {
    digitalWrite(Switch, HIGH);
    delay(3000);
    digitalWrite(Switch, LOW);
  }
}