Newbie: Toggling LEDS

Hi, I am currently working on a small simulation for an HVAC Project where each LED represents an air conditioning unit. Here is the sequence of operation:

  1. Two LEDS (labeled AC3, AC4) will toggle with a delay of 1s for each transition period

  2. If I trigger a fault to an LED by setting my dip switch to LOW, it will automatically turn on the second LED and turn the first LED off. Basically, each LED is a backup to one another.

The problem I am having is that when I set ACState1 LOW, it will blink the second LED (AC4) once then remain on. If I set ACState1 back to HIGH, both LED's will stay on momentarily, then begin to toggle.

However, I am not having this problem when ACState2 is set to LOW. If I set it LOW, it will turn on the first LED (AC3) and stay on with no blinking. If I set it back to back to HIGH, LED (AC3) will turn off first then begin to toggle as expected.

Here is my code:

 int AC3 = 8;
 int AC4 = 9;
 int AC3Fault = 4;
 int AC4Fault = 3;
 int ACState1;
 int ACState2;

 void setup()
 { 
  
   pinMode(AC3, OUTPUT); // set digital pin as OUTPUT
   pinMode(AC4, OUTPUT);
   pinMode(AC3Fault, INPUT);
   pinMode(AC4Fault, INPUT);
 }

 void loop()
 {
      
    ACState1 = digitalRead(AC3Fault);
    ACState2 = digitalRead(AC4Fault);
    
    if (ACState1 == HIGH && ACState2 == HIGH){ //if both HIGH, begin to toggle
     toggleAC();
    }else if (ACState1 == LOW){ //if first state low, turn AC4 LED on
        digitalWrite(AC4,HIGH);
    }else if (ACState2 == LOW){// if second state low, turn AC3 LED on
        digitalWrite(AC3,HIGH);

    }
}

void toggleAC(){//toggle AC units for one second
    
     digitalWrite(AC3, HIGH);
     delay(1000);
     digitalWrite(AC3, LOW);
     delay(1000);
     digitalWrite(AC4, HIGH);
     delay(1000);
     digitalWrite(AC4, LOW);
     delay(1000);
  }//

Any ideas? Thanks you guys.

Any ideas?

As always, get rid of “delay()”

AWOL:

Any ideas?

As always, get rid of "delay()"

Hi AWOL,

I completely left out the part why I need the delay there. I set a one second delay to represent a week. Every week one AC unit will turn off and another will turn on. If I get rid of the delay in my toggleAC() function, won't they both flash at a really high rate? Thanks.

Yes they will. Now read, play with and really understand the blink without delay example supplied with the IDE.

http://www.gammon.com.au/blink