This is my code with a schematic as an attachment
I'am using an existing door opener sequencer board and adding this control into the push button control and using existing up and down, pull down limit switches. The uplimit switch is wired in series with the A_delay and B_delay time inputs on a SPDT switch. The up and down limit switch is then used as posistion indicators. My problem is it runs the delay fine with just one delay written into the code , As soon as the second delay is added it will not see it.
//Global Variables
//pins used 2( up indi), 3(PB), 7(relay1in), 6(B_in), 5(A_in), 4(dn indi), 12(relay), 10(dn LS), 9(up LS), 8(relay2in)
//input pins
const byte buttonPin=3; //manual door control
const byte A_Delay=5; //A_Delay timer engage
const byte B_Delay=6; //B_Delay timer engage
const int limitDnPin=9; //door in down posistion
const int limitUpPin=10; //door is in up posistion
int limitDnState=0; //down limit switch set at lo
int buttonState=0; //button set at lo
int limitUpState=0;
// output pins
const byte relay=12; //door motor run
const int relay1In=7;
const int relay2In=8; //door raised indicator
const int doorDn=4; //door closed indicator
const int doorUp=2; //door open indicator
unsigned long limitUpMillis; //when limit up switch closed
unsigned long relay_1TurnedOnAt; //when relay was turned on
unsigned long relay_2TurnedOnAt; //when relay was turned on
unsigned long A_DelayMillis; //switch state change
unsigned long A_TurnOnDelay = 2000; //wait to turn on relay
unsigned long A_TurnOffDelay = 500; //turn off relay after this time
unsigned long B_DelayMillis; //switch state change
unsigned long B_TurnOnDelay = 3000; //wait to turn on relay
unsigned long B_TurnOffDelay = 500; //turn off relay after this time
bool relay1InReady = false; // flag for when button is let go
bool relay1InState = false; // for relay is on or not.
bool relay2InReady = false; // flag for when button is let go
bool relay2InState = false; // for relay is on or not.
void setup() {
pinMode(limitUpPin,INPUT); //sets door Up switch as input
pinMode(limitDnPin,INPUT); //sets door Dn switch as input
pinMode(buttonPin, INPUT_PULLUP); //manual door control
pinMode (relay1In,OUTPUT);
pinMode(relay2In,OUTPUT); //door up posistion indicator
pinMode(doorDn,OUTPUT); //door closed indicator
pinMode(relay, OUTPUT); //door motor run
pinMode(A_Delay, INPUT_PULLUP); //auto delayed close A_
pinMode(B_Delay, INPUT_PULLUP); //auto delayed close B_
digitalWrite(relay, LOW);
}
void loop() {
// get the time at the start of this loop()
unsigned long currentMillis = millis();
//Manual door operations
buttonState=digitalRead(buttonPin); //test button state hi or lo
if (buttonState == LOW ) //when button pushed
digitalWrite(relay,HIGH); //turn relay on
else { digitalWrite(relay,LOW); } //turn relay off
limitDnState=digitalRead(limitDnPin); //test down switch for state hi or lo
if ( limitDnState == LOW ) //when the switch is closed (door down)
digitalWrite(doorDn,HIGH); //turn closed indicator on
else { digitalWrite(doorDn,LOW); } //leave closed indicator off
limitUpState= digitalRead(limitUpPin);
if (limitUpState == LOW)
digitalWrite(doorUp,HIGH);
else { digitalWrite(doorUp,LOW); }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this is auto time close for A_Dlay function,
//triggered with the door open limit switch in series
// check the switch
if (digitalRead(A_Delay) == HIGH) {
// update the time when the switch was closed
limitUpMillis = currentMillis;
relay1InReady = true;
}
if (relay1InReady) {
//this is typical millis code here:
if ((unsigned long)(currentMillis - limitUpMillis) >= A_TurnOnDelay) {
// time has passed since the switch was closed
digitalWrite(relay1In, HIGH);
relay1InState = true;
// save when the relay turned on
relay_1TurnedOnAt = currentMillis;
relay1InReady = false;
}
}
// see if we are watching for the time to turn off relay
if (relay1InState) {
// relay on, check time
if ((unsigned long)(currentMillis - relay_1TurnedOnAt) >= A_TurnOffDelay) {
relay1InState = false;
digitalWrite(relay1In, LOW);
}
}
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//this is auto time close for B_Dlay function,
//triggered with the door open limit switch in series
// check the switch
if (digitalRead(B_Delay) == HIGH); {
// update the time when the switch was closed
limitUpMillis = currentMillis;
relay2InReady = true;
}
if (relay2InReady) {
//this is typical millis code here:
if ((unsigned long)(currentMillis - limitUpMillis) >= B_TurnOnDelay) {
// time has passed since the switch was closed
digitalWrite(relay2In, HIGH);
relay2InState = true;
// save when the relay turned on
relay_2TurnedOnAt = currentMillis;
relay2InReady = false;
}
}
// see if we are watching for the time to turn off relay
if (relay2InState) {
// relay on, check time
if ((unsigned long)(currentMillis - relay_2TurnedOnAt) >= B_TurnOffDelay) {
relay2InState = false;
digitalWrite(relay2In, LOW);
}
}
}