//-----LIGHT PINS-----
const int BlockLT = 2;
const int EstopLT = 22;
const int ResetLT = 23;
const int StationLT = 24;
const int LiftLT = 25;
const int WaitLT = 26;
const int LstopLT = 27;
const int ReintLT = 28;
const int DispatchLT = 29;
//-----BUTTON PINS-----
const int EstopBT = 30;
const int ResetBT = 31;
const int ModeBT = 32;
const int LstopBT = 33;
const int ReintBT = 34;
const int JogBT = 35;
const int DispatchBT = 36;
//-----MOTOR PINS-----
const int LiftMotor = 52;
const int StationMotor = A15;
const int BlockMotor = 50;
const int WaitMotor = 51;
//------PHOTOEYE PINS-----
const int LiftEye = A0;
const int BlockEye = A1;
const int WaitEye = A2;
const int StationEye = A3;
//-----BRAKE PINS-----
const int LWaitBrake = 49;
const int RWaitBrake = 47;
const int StationBrake = 53;
//-----ALL ZONES OCCUPIED-----
boolean StationOCC = true;
boolean LiftOCC = true;
boolean BlockOCC = true;
boolean WaitOCC = true;
//-----VARIABLES-----
boolean ReintPRO = false; //Begin Initalizing Process
boolean CascadePRO;
boolean EstopPRO = false; //Estop Active When 'true'
boolean LstopPRO = false; //Lstop Active When 'true'
boolean DispatchPRO = false;
int EstopLIT = LOW;
int LstopLIT = LOW;
int DispatchLIT;
//-----TIMERS-----
long previousMillis = 0;
long EstopInterval = 250;
long LstopInterval = 250;
long DispatchInterval = 750;
void setup(){
//-----LIGHT PIN SETUP-----
pinMode(BlockLT, OUTPUT);
pinMode(EstopLT, OUTPUT);
pinMode(ResetLT, OUTPUT);
pinMode(StationLT, OUTPUT);
pinMode(LiftLT, OUTPUT);
pinMode(WaitLT, OUTPUT);
pinMode(LstopLT, OUTPUT);
pinMode(ReintLT, OUTPUT);
pinMode(DispatchLT, OUTPUT);
//-----BUTTON PIN SETUP-----
pinMode(EstopBT, INPUT_PULLUP);
pinMode(ResetBT, INPUT_PULLUP);
pinMode(ModeBT, INPUT_PULLUP);
pinMode(LstopBT, INPUT_PULLUP);
pinMode(ReintBT, INPUT_PULLUP);
pinMode(JogBT, INPUT_PULLUP);
pinMode(DispatchBT, INPUT_PULLUP);
//-----MOTOR PIN SETUP-----
pinMode(LiftMotor, OUTPUT);
pinMode(StationMotor, OUTPUT);
pinMode(BlockMotor, OUTPUT);
pinMode(WaitMotor, OUTPUT);
//-----PHOTOEYE PIN SETUP-----
pinMode(LiftEye, INPUT);
pinMode(BlockEye, INPUT);
pinMode(WaitEye, INPUT);
pinMode(StationEye, INPUT);
//-----BRAKE PIN SETUP-----
pinMode(LWaitBrake, OUTPUT);
pinMode(RWaitBrake, OUTPUT);
pinMode(StationBrake, OUTPUT);
}
void loop(){
//Starting Millis Timer
unsigned long currentMillis = millis();
//Reading Button Values
int EstopVAL = digitalRead(EstopBT);
int DispatchVAL = digitalRead(DispatchBT);
int ReintVAL = digitalRead(ReintBT);
int LstopVAL = digitalRead(LstopBT);
int JogVAL = digitalRead(JogBT);
int ResetVAL = digitalRead(ResetBT);
int StationEyeVAL = digitalRead(StationEye);
int LiftEyeVAL = digitalRead(LiftEye);
int BlockEyeVAL = digitalRead(BlockEye);
int WaitEyeVAL = digitalRead(WaitEye);
int ModeVAL = digitalRead(ModeBT);
//-----SYSTEM IN MAINT MODE-----
if (ModeVAL == HIGH){
//Use Dispatch Button to Test Block Motor
if (DispatchVAL == LOW){
digitalWrite(BlockMotor, HIGH);}
else{
digitalWrite(BlockMotor, LOW);}
//Use Initalize Button to Test Station Motor
if (ReintVAL == LOW){
digitalWrite(StationMotor, HIGH);}
else{
digitalWrite(StationMotor, LOW);}
//Use Reset Button to Test Station Brake
if (ResetVAL == LOW){
digitalWrite(ResetLT, HIGH);
digitalWrite(StationBrake, HIGH);}
else{
digitalWrite(ResetLT, LOW);
digitalWrite(StationBrake, LOW);}
//Use LiftStop Button to Test Lift Motor
if (LstopVAL == LOW){
digitalWrite(LstopLT, HIGH);
digitalWrite(LiftMotor, LOW);}
else{
digitalWrite(LstopLT, LOW);
digitalWrite(LiftMotor, HIGH);}
//Photoeye at Station Test
if (StationEyeVAL == LOW){
digitalWrite(StationLT, HIGH);}
else{
digitalWrite(StationLT, LOW);}
//Photoeye at Lift Test
if (LiftEyeVAL == LOW){
digitalWrite(LiftLT, HIGH);}
else{
digitalWrite(LiftLT, LOW);}
//Photoeye at Block Test
if (BlockEyeVAL == LOW){
digitalWrite(BlockLT, HIGH);}
else{
digitalWrite(BlockLT, LOW);}
//Photoeye at Wait Test
if (WaitEyeVAL == LOW){
digitalWrite(WaitLT, HIGH);}
else{
digitalWrite(WaitLT, LOW);}
//Wait Brake Test
if (JogVAL == LOW){
digitalWrite(RWaitBrake, HIGH);
digitalWrite(LWaitBrake, HIGH);
digitalWrite(EstopLT, HIGH);}
else{
digitalWrite(LWaitBrake, LOW);
digitalWrite(RWaitBrake, LOW);
digitalWrite(EstopLT, LOW);}
if (JogVAL == HIGH && WaitEyeVAL == LOW){
digitalWrite(WaitMotor, HIGH);
delay(1200);}
else{
digitalWrite(WaitMotor, LOW);}
}
//-----SYSTEM IN AUTO MODE-----
else{
//-----*****EMERGENCY STOP MODE*****-----
if (EstopVAL == LOW){
EstopPRO = true;}
if (EstopPRO == true){
digitalWrite(LiftMotor, LOW);
digitalWrite(BlockMotor, LOW);
digitalWrite(WaitMotor, LOW);
digitalWrite(StationMotor, LOW);
digitalWrite(RWaitBrake, HIGH);
digitalWrite(LWaitBrake, HIGH);
digitalWrite(StationBrake, HIGH);
digitalWrite(LstopLT, HIGH);
if(currentMillis - previousMillis > EstopInterval){//Estop Blinking
previousMillis = currentMillis;
if (EstopLIT == LOW){
EstopLIT = HIGH;}
else{
EstopLIT = LOW;}
digitalWrite(EstopLT, EstopLIT);}}
//-----*****LIFT STOP MODE*****-----
if (LstopVAL == LOW){
LstopPRO = true;}
if (LstopPRO == true){
digitalWrite(LiftMotor, LOW);
if(currentMillis - previousMillis > LstopInterval){//Lift Stop Blinking
previousMillis = currentMillis;
if (LstopLIT == LOW){
LstopLIT = HIGH;}
else{
LstopLIT = LOW;}
digitalWrite(LstopLT, LstopLIT);}}
//-----*****FAULT RESETING*****-----
if (EstopPRO == true && EstopVAL == HIGH){
digitalWrite(ResetLT, HIGH);}
if (LstopPRO == true && LstopVAL == HIGH){
digitalWrite(ResetLT, HIGH);}
if (ResetVAL == LOW && EstopVAL == HIGH && LstopVAL == HIGH){
EstopPRO = false;
LstopPRO = false;
digitalWrite(EstopLT, LOW);
digitalWrite(LstopLT, LOW);
digitalWrite(ResetLT, LOW);}
//Indicates initalization needs to be performed when all blocks are occupied
if (StationOCC == true && LiftOCC == true && BlockOCC == true && WaitOCC == true){
digitalWrite(ReintLT, HIGH);}
//Occupied lights on when zone is occupied
if (StationOCC == true){
digitalWrite(StationLT, HIGH);}
if (LiftOCC == true){
digitalWrite(LiftLT, HIGH);}
if (BlockOCC == true){
digitalWrite(BlockLT, HIGH);}
if (WaitOCC == true){
digitalWrite(WaitLT, HIGH);}
//-----*****DISPATCHING FROM STATION*****-----
//-----*****TRAIN IN LIFT ZONE*****-----
//-----*****TRAIN IN BLOCK ZONE*****-----
if(BlockEyeVAL == LOW && EstopPRO == false && WaitOCC == false){
digitalWrite(BlockMotor, HIGH);}
else{
digitalWrite(BlockMotor, LOW);}
//-----*****TRAIN IN HOLD ZONE*****------
}
}
Here is my code. The area where I am having an issue is at the end.