Hi Folks
getting there but now i have run into a timer loop.
first run works fine and code compiles ok.
but last three segments call a IF function that already true due to the prior run.
would like to know where to look or how to reset or stop at end of successful run
Thanks in anticipation
Gate 1.2
/*
Made to run on Arduino uno clone
this code is to run linear actuators with out position sensors
but have inbuild stop switches in actuators
to be used as auto gate openers
useing 2 H bridge units to drive
delay time is to allow sufficent run time to open or close gates
overrun is not a concern as actuators stop at limits
*/
unsigned long Traffic; // traffic timer
unsigned long CloseGate; //Start time of timer
unsigned long StartHold; //Start time of timer
unsigned long Current_Time; // as states
const unsigned long GateRun = 10000; //reStart gates
const unsigned long GateHold = 20000; //Pause timer for traffic
const unsigned long RunTime = 20000; //run timer for gate motion
int pedestrian = 3; //open small gate only
int OpenGates = 4; // open both gates
int stopfeedA = 5; // sensor eye A to digital pin 5
int stopfeedB = 6; // sensor eye B to digital pin 6
int OpenGate2 = 7; // open gate to motor2 digital pin 7
int OpenGate1 = 8; // open gate to motor1 on digital pin 8
int CloseGate1 = 9; // close gate to motor1 on digital pin 9
int CloseGate2 = 10; // close gate to motor2 on digital pin 10
int end = 0;
void setup()
{
Serial.begin(9600);
pinMode(OpenGate2, OUTPUT); // open gate 2
pinMode(OpenGate1, OUTPUT); // open gate 1
pinMode(CloseGate1, OUTPUT); // Close Gate 1
pinMode(CloseGate2, OUTPUT); // Close Gate 2
pinMode(stopfeedB, INPUT_PULLUP); // EMERGENCY STOP GATES
pinMode(stopfeedA, INPUT_PULLUP); // EMERGENCY STOP GATES
pinMode(OpenGates, INPUT_PULLUP); // OPEN GATES
}
void loop()
{
Current_Time = millis(); //get the current "time"
// ////////////////THIS SECTION TO RUN MAIN GATES//////////////////////
if (digitalRead(OpenGates) == LOW)
{
// Open Gates
digitalWrite(OpenGate1, HIGH);
digitalWrite(OpenGate2, HIGH);
// Gate close timer
StartHold = millis();
Serial.println("GateRun started and gates opening");
}
// test whether the period has elapsed
if (Current_Time - StartHold >= GateRun)
{
Serial.println("timer already finished gate run stop");
// shutdown gates
digitalWrite(OpenGate1, LOW);
digitalWrite(OpenGate2, LOW);
// Gate traffic timer
Traffic = millis();
}
// /////// This section is to reclose Gates after being opened //////
// test whether the period has elapsed
if (Current_Time - Traffic >= GateHold)
{
Serial.println("Traffic Delay already finished.Gates Closing now");
// close gates
digitalWrite(CloseGate1, HIGH);
digitalWrite(CloseGate2, HIGH);
// Gate hold timer = millis();
CloseGate = millis();
}
// test whether the period has elapsed
if (Current_Time - CloseGate >= GateRun)
{
Serial.println("Gates Shut down ready for re run");
// shut down gates
digitalWrite(CloseGate1, LOW);
digitalWrite(CloseGate2, LOW);
}
// ///////// THIS SECTION IS EMERGENCY STOP ///////////////
if (digitalRead(stopfeedB) == LOW)
{
Serial.println("Emergency stop B pressed stops gates");
digitalWrite(OpenGate1, LOW);
digitalWrite(OpenGate2, LOW);
digitalWrite(CloseGate1, LOW);
digitalWrite(CloseGate2, LOW);
}
if (digitalRead(stopfeedA) == LOW)
{
Serial.println("Emergency stop A pressed stops gates");
digitalWrite(CloseGate1, LOW);
digitalWrite(CloseGate2, LOW);
digitalWrite(OpenGate1, LOW);
digitalWrite(OpenGate2, LOW);
}
Serial.println("end script and rerun");
}