// constants won't change. They're used here to set pin numbers:
const int Cyl_Left_Relay_Pin = 7; // Left cyl
const int Cyl_Right_Relay_Pin = 6; // Right cyl
const int Cyl_Drop_Relay_Pin = 5; // drop cyl
const int Cyl_Pre_Relay_Pin = 4; // Pre cyl
const int Error_Led_Pin = 3; // Error Led
const int Pre_Drop = 13; // pre drop miccroswitch
const int Left_Home = 12; // Left home Micro switch
const int Left_Extended = 11; // Left Extend Micro switch
const int EMERGENCY_STOP = 10; // GreenYellow button
const int Right_Home = 9; // Right Home Micro switch
const int Right_Extend = 8; // Right extend Micro switch
const int Cush_Confirm = 2; // crushed can drop confirm Micro switch
const int Btn_R = 1; // GreenYellow button Micro switch
byte Pre_Drop_PinState;
byte Left_Home_PinState;
byte Left_Extended_PinState;
byte EMERGENCY_STOP_PinState;
byte Right_Home_PinState;
byte Right_Extend_PinState;
byte Cush_Confirm_PinState;
byte Btn_R_PinState;
void setup() {
// initialize the Relays pins as an output:
pinMode(Cyl_Left_Relay_Pin, OUTPUT);
pinMode(Cyl_Right_Relay_Pin, OUTPUT);
pinMode(Cyl_Drop_Relay_Pin, OUTPUT);
pinMode(Cyl_Pre_Relay_Pin, OUTPUT);
pinMode(Error_Led_Pin, OUTPUT);
pinMode(Pre_Drop, INPUT_PULLUP);
pinMode(Left_Home, INPUT_PULLUP);
pinMode(Left_Extended, INPUT_PULLUP);
pinMode(EMERGENCY_STOP, INPUT_PULLUP);
pinMode(Right_Home, INPUT_PULLUP);
pinMode(Right_Extend, INPUT_PULLUP);
pinMode(Cush_Confirm, INPUT_PULLUP);
pinMode(Btn_R, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
// digitalWrite(Cyl_Drop_Relay_Pin, LOW);
read_inputs();
delay(30);
feed_can();
}
void read_inputs() {
Pre_Drop_PinState = digitalRead(Pre_Drop);
Left_Home_PinState = digitalRead(Left_Home);
Left_Extended_PinState = digitalRead(Left_Extended);
EMERGENCY_STOP_PinState = digitalRead(EMERGENCY_STOP);
Right_Home_PinState = digitalRead(Right_Home);
Right_Extend_PinState = digitalRead(Right_Extend);
Cush_Confirm_PinState = digitalRead(Cush_Confirm);
Btn_R_PinState = digitalRead(Btn_R);
}
void feed_can() {
// check can in pre drop, check both crush cyl at Extended position
if (Pre_Drop_PinState == HIGH && Left_Extended_PinState == HIGH && Right_Extend_PinState == HIGH){
// drop can
digitalWrite(Cyl_Drop_Relay_Pin, HIGH);}
else{
digitalWrite(Cyl_Drop_Relay_Pin, LOW);
// check if any of can in pre drop, or both crush cyl not at extend position
if (Pre_Drop_PinState == LOW || Left_Extended_PinState == LOW||Right_Extend_PinState == LOW)
}
}
ErrLed();
}
void ErrLed() {
digitalWrite(Error_Led_Pin, HIGH);
delay(500);
digitalWrite(Error_Led_Pin, LOW);
delay(500);
digitalWrite(Error_Led_Pin, HIGH);
delay(500);
digitalWrite(Error_Led_Pin, LOW);
}