ky-032

hi all below is a code i have trying to modify,
is ther a way of the ky-032 flashing 2 leds led 1 on led 2 off, as i want to use this on my model railway to warning lights when train gets to a certian point

int ledRed = 8;
int ledGreen = 4;
int avoidance = 12;
int cmd;
unsigned long secs = 0;
int interval = 1000;
unsigned long previousMillis = 0;

void setup(){
pinMode(ledRed, OUTPUT);
digitalWrite(8, LOW);
pinMode(ledGreen, OUTPUT);
digitalWrite(4, HIGH);
pinMode(avoidance, INPUT);
//serial.begin(9600);
}
void loop (){
cmd = digitalRead(avoidance);
unsigned long currentMillis = millis();
if ((unsigned long)(currentMillis - previousMillis) >= interval)
{
previousMillis = millis();
secs = secs + 1;
}
if(cmd == LOW)
{
secs = 0;
digitalWrite(8, HIGH);
digitalWrite(4, LOW);
}
if(cmd == HIGH && secs == 5)
{
digitalWrite(8, LOW);
digitalWrite(4, HIGH);
}
}

Like this ??

byte RedLed = 8;
byte GreenLed = 4;
byte avoidance = 12;
byte cmd;
unsigned long next; // next is time to switch lights
int interval = 500;

void setup(){
  pinMode(RedLed, OUTPUT);  
  pinMode(GreenLed, OUTPUT);  // steady green when no obstacle present ??
  pinMode(avoidance, INPUT);
  //serial.begin(9600);
  }
void loop ()
{
  cmd = digitalRead(avoidance);  // check for obstacle
  if (cmd==1) // HIGH= no obstacle => give green light
  {
    digitalWrite(RedLed, LOW);
    digitalWrite(GreenLed, HIGH); // steady green when no obstacle present ??
  }
  else // stop!! start blinking red/green
  {
    if (millis()>next)
    {
      next=millis()+interval;
      digitalWrite(RedLed, !digitalRead(RedLed));  // switch on/off  both LEDs
      digitalWrite(GreenLed, !digitalRead(GreenLed));
    }
  }
}