Help with delay timing

Hi Everyone,
I am extremely new to Arduino. I have been reading and studying examples. I got a sketch pretty well done but it is causing me some grief. I have two pairs of inputs and outputs. I was input 1 to trigger output 2 and input 2 to trigger output 1. The one bit of logic I want to add is if input 2 is doing the triggering, when its done I want it to delay input 1 by 5 seconds. I wrote a sketch that I thought would do this but the issue is it is applying a 5 second delay to both inputs. Plus it is delaying not only input high but input low as well. I only want input 2 when changing from high to low to delay input 1 by 5 seconds when going high. Hopefully I was able to convey by intent well enough. Here is what I got so far..
Thanks,
Cory

const int RadioCOSPin = 2;
const int RadioPTTPin = 3;
const int PCPTTPin = 4;
const int PCCOSPin = 5;
int RadioCOSState = 0;
int PCCOSState = 0;
int PCPTTDelay = 0;

void setup() 
{
    pinMode(RadioPTTPin, OUTPUT);
    pinMode(RadioCOSPin, INPUT);
    pinMode(PCPTTPin, OUTPUT);
    pinMode(PCCOSPin, INPUT);
}

void loop()
{
    {
    RadioCOSState = digitalRead(RadioCOSPin);
        if (RadioCOSState == HIGH && PCPTTDelay == 0)
        {
        digitalWrite(PCPTTPin, LOW);
        }
        else 
        {
        digitalWrite(PCPTTPin, HIGH);
        }
    }
    
    {
    PCCOSState = digitalRead(PCCOSPin);
        if (PCCOSState == HIGH)
        {
        digitalWrite(RadioPTTPin, LOW);
        digitalWrite(PCPTTDelay, 1);
        }
        else
        {
        digitalWrite(RadioPTTPin, HIGH);
        delay(1000);
        digitalWrite(PCPTTDelay, 0);
        } 
    }
}

It would help if you

Corymacs:
I have two pairs of inputs and outputs. I want input 1 to trigger output 2 and input 2 to trigger output 1.

const int RadioCOSPin = 2;

const int RadioPTTPin = 3;
const int PCPTTPin = 4;
const int PCCOSPin = 5;

It would help if you used the same pin names in your requirements document as you do in your sketch. I know PTT stands for Push To Talk but what does COS stand for?

It would help to avoid using delay(...) and use timing based on millis().

COS stands for Carrier Operated Squelch. What I want to happen is when the Squelch is broken on one radio it transmits on the other radio. The only issue when the PTT ends on the one radio the other radio has a momentary squelch break for 2 seconds after. So I don't want that to cause a unnecessary PTT. That's why I want the delay. How would I use timing instead of delay? Sorry, I'm very new with coding. The only reason I have gotten this far is by studying examples and trying to copy some code.

Ok, I re-did my program in an attempt to use millis instead of delay. I spent a day pulling my hair out researching different examples and I can't get it to work. Right now my inputs and outputs function flawlessly. This issue is I have no delay on the PCPTTPin. The outputs switch as if the millis timer isn't even there. Can anyone give me some helpful advice.
Thanks in advance. Here is my code thus far...

const int RadioCOSPin = 2;
const int RadioPTTPin = 3;
const int PCPTTPin = 4;
const int PCCOSPin = 5;
int RadioCOSState = LOW;
int PCCOSState = LOW;
int PCPTTDelay = 0;
unsigned long currentMillis = 0;
unsigned long interval = 5000;

void setup() 
{
    pinMode(RadioPTTPin, OUTPUT);
    pinMode(RadioCOSPin, INPUT);
    pinMode(PCPTTPin, OUTPUT);
    pinMode(PCCOSPin, INPUT);
}

void loop()
{
   {
    PCCOSState = digitalRead(PCCOSPin);
        if (PCCOSState == HIGH)
        { 
        digitalWrite(RadioPTTPin, LOW);
        }
        else
        {
        digitalWrite(RadioPTTPin, HIGH);
        currentMillis = millis();
   } 
   {
    RadioCOSState = digitalRead(RadioCOSPin);
        if ((RadioCOSState == HIGH) && ((unsigned long)(millis() - currentMillis >= interval)))
        {
        digitalWrite(PCPTTPin, LOW);
        }
        else 
        {
        digitalWrite(PCPTTPin, HIGH);
        }
    }
    

    }
}
if ((RadioCOSState == HIGH) && ((unsigned long)(millis() - currentMillis >= interval)))

The cast (unsigned long) is wrong; it takes a comparison that has a boolean result and converts it to an unsigned long. It probably works correctly anyway but should be removed.

millis(), currentMillis, and interval are all declared as unsigned long so any additional casts should be unnecessary.

I removed what you suggested. Do you have any other suggestions as to why it might not be working?
Here is the new code with the change...

const int RadioCOSPin = 2;
const int RadioPTTPin = 3;
const int PCPTTPin = 4;
const int PCCOSPin = 5;
int RadioCOSState = LOW;
int PCCOSState = LOW;
int PCPTTDelay = 0;
unsigned long currentMillis = 0;
unsigned long interval = 5000;

void setup() 
{
    pinMode(RadioPTTPin, OUTPUT);
    pinMode(RadioCOSPin, INPUT);
    pinMode(PCPTTPin, OUTPUT);
    pinMode(PCCOSPin, INPUT);
}

void loop()
{
   {
    PCCOSState = digitalRead(PCCOSPin);
        if (PCCOSState == HIGH)
        { 
        digitalWrite(RadioPTTPin, LOW);
        }
        else
        {
        digitalWrite(RadioPTTPin, HIGH);
        currentMillis = millis();
   } 
   {
    RadioCOSState = digitalRead(RadioCOSPin);
        if ((RadioCOSState == HIGH) && ((millis() - currentMillis >= interval)))
        {
        digitalWrite(PCPTTPin, LOW);
        }
        else 
        {
        digitalWrite(PCPTTPin, HIGH);
        }
    }
    

    }
}

ok, So it seems to be working. The only issue is when PCCOSState is low the PCPTTPin wont change. So it seems like the timer code is running continuously. How can I make it run once after the PCCOSState goes low. Right now it seems like when the PCCOSState goes low it continuously updates currentMillis. I want it to update currentMillis just the once.

vaj4088:

if ((RadioCOSState == HIGH) && ((unsigned long)(millis() - currentMillis >= interval)))

The cast (unsigned long) is wrong; it takes a comparison that has a boolean result and converts it to an unsigned long. It probably works correctly anyway but should be removed.

millis(), currentMillis, and interval are all declared as unsigned long so any additional casts should be unnecessary.

The casting is good just in the wrong spot:

if ((RadioCOSState == HIGH) && ((unsigned long) (millis() - currentMillis) >= interval))

My Blink without delay timer for spam protection:

  static unsigned long SpamTimer;
  if ( (unsigned long)(millis() - SpamTimer) >= (t)) {
    SpamTimer= millis();

  }

Z

zhomeslice wrote (in part):

The casting is good just in the wrong spot:

if ((RadioCOSState == HIGH) && ((unsigned long) (millis() - currentMillis) >= interval))

except that millis() and currentMillis are already declared as unsigned long, so the subtraction results in an unsigned long, so now the cast is not wrong but is unnecessary (and harmless).

Thanks everyone for all your help. I finally got it working. I don't think I have any hair left but I have learned a lot. Here is the code I ended with. Feel free to offer any suggestions if there is something that doesn't look right. Thanks.

const int RadioCOSPin = 2;
const int RadioPTTPin = 3;
const int PCPTTPin = 4;
const int PCCOSPin = 5;
int RadioCOSState = LOW;
int PCCOSState = LOW;
boolean Disable = false;
unsigned long currentMillis = 0;
unsigned long interval = 5000;

void setup() 
{
    pinMode(RadioPTTPin, OUTPUT);
    pinMode(RadioCOSPin, INPUT);
    pinMode(PCPTTPin, OUTPUT);
    pinMode(PCCOSPin, INPUT);
}

void loop()
{
   {
    PCCOSState = digitalRead(PCCOSPin);
        if ((PCCOSState == LOW) && (Disable == false))
        {
        currentMillis = millis();
        }
   }
   {
    PCCOSState = digitalRead(PCCOSPin);
        if (PCCOSState == HIGH)
        { 
        digitalWrite(RadioPTTPin, LOW);
        Disable = false;
        }
        else
        {
        digitalWrite(RadioPTTPin, HIGH);
        Disable = true;
        } 
   }
   {
    RadioCOSState = digitalRead(RadioCOSPin);
        if ((RadioCOSState == HIGH) && ((millis() - currentMillis >= interval)))
        {
        digitalWrite(PCPTTPin, LOW);
        }
        else 
        {
        digitalWrite(PCPTTPin, HIGH);
        }
    }
}