const int dir1 = 12;//direction of a motor conect direclty to controler
const int dir2 = 11;//direction of a motor conect direclty to controler
const int pwm1 = 10;//start motors
const int pwm2 = 9;//start motor
const int CloseGateButton = 8;//signal from master to close gates
const int OpenGateButton = 7;//signal from master to open gates
const int OneGateOpenButton = 6;//signal to open 1 gate directly conceted to slave
const int AutoButtun = 5;//auto signal will be coming from master to slave
const int OpenLed = 4;// signal will be tellign master if gates are operating direcly conect to master
const int CloseLed = 3;//signal telling master if gates are operating
int GateTimer = 30000; // Adjust as needed
void setup() {
// Initialize pin modes
pinMode(pwm1, OUTPUT);
pinMode(pwm2, OUTPUT);
pinMode(dir1, OUTPUT);
pinMode(dir2, OUTPUT);
pinMode(OpenLed, OUTPUT);
pinMode(CloseLed, OUTPUT);
pinMode(CloseGateButton, INPUT);
pinMode(OpenGateButton, INPUT);
pinMode(OneGateOpenButton, INPUT);
pinMode(AutoButtun, INPUT);
}
void loop() {
if(digitalRead(AutoButtun)== HIGH){
// Open both gates
digitalWrite(OpenLed,HIGH);
analogWrite(pwm1, 50);
analogWrite(pwm2, 0);
delay(2000); // Delay to debounce button
analogWrite(pwm2, 50);
delay(1000);
analogWrite(pwm1, 250);
analogWrite(pwm2, 250);
delay(GateTimer); // Open for GateTimer milliseconds
analogWrite(pwm1, 50); // Slow down
delay(2000);
analogWrite(pwm2, 50); // Slow down the second gate
delay(2000); // Continue slowly for 2 seconds
analogWrite(pwm1, 0); // Stop gate 1
analogWrite(pwm2, 0); // Stop gate 2
delay(200); // Delay to debounce button
digitalWrite(OpenLed,LOW);
delay(10000);
digitalWrite(CloseLed,HIGH);
digitalWrite(dir1, HIGH);
digitalWrite(dir2, HIGH);
analogWrite(pwm1, 50);
analogWrite(pwm2, 50);
delay(1000); // Delay to debounce button
analogWrite(pwm1, 250);
analogWrite(pwm2, 250);
delay(2000); // Close for 2 seconds
delay(GateTimer); // Close for GateTimer milliseconds
analogWrite(pwm1, 50); // Slow down
delay(2000);
analogWrite(pwm2, 50); // Slow down the second gate
delay(2000); // Continue slowly for 2 seconds
analogWrite(pwm1, 0); // Stop gate 1
analogWrite(pwm2, 0); // Stop gate 2
digitalWrite(dir1, LOW); // Set direction to low (assuming this is how you stop)
digitalWrite(dir2, LOW); // Set direction to low (assuming this is how you stop)
delay(200); // Delay to debounce button
digitalWrite(CloseLed,LOW);
delay(200);
}
if (digitalRead(OneGateOpenButton) == HIGH) {
// Open one gate
digitalWrite(OpenLed,HIGH);
analogWrite(pwm1, 50);
delay(1000);
analogWrite(pwm1, 250);
delay(30000); // Open for 30 seconds
digitalWrite(OpenLed,LOW);
delay(10000);
digitalWrite(CloseLed,HIGH);
digitalWrite(dir1, HIGH);
analogWrite(pwm1, 50);
delay(1000);
analogWrite(pwm1, 250);
delay(30000); // Reverse direction for 19 seconds
analogWrite(pwm1, 50); // Slow down
delay(2000); // Continue slowly for 2 seconds
analogWrite(pwm1, 0); // Stop
digitalWrite(dir1, LOW); // Set direction to low (assuming this is how you stop)
delay(200); // Delay to debounce button
digitalWrite(CloseLed,LOW);
delay(200);
}
if (digitalRead(CloseGateButton) == HIGH) {//gate 2 main gate pwm 2
// Close both gates
digitalWrite(CloseLed,HIGH);
digitalWrite(dir1, HIGH);
digitalWrite(dir2, HIGH);
analogWrite(pwm2, 50);
analogWrite(pwm1, 00);
delay((2000);
analogWrite(pwm1, 250);
analogWrite(pwm2, 250);
delay(GateTimer); // Close for GateTimer milliseconds
analogWrite(pwm2, 50); // Slow down
delay(2000);
analogWrite(pwm1, 50); // Slow down the second gate
delay(2000); // Continue slowly for 2 seconds
analogWrite(pwm1, 0); // Stop gate 1
analogWrite(pwm2, 0); // Stop gate 2
digitalWrite(dir1, LOW); // Set direction to low (assuming this is how you stop)
digitalWrite(dir2, LOW); // Set direction to low (assuming this is how you stop)
delay(200); // Delay to debounce button
digitalWrite(CloseLed,LOW);
delay(200);
}
if (digitalRead(OpenGateButton) == HIGH) {
// Open both gates
digitalWrite(OpenLed,HIGH);
analogWrite(pwm1, 50);
analogWrite(pwm2, 50);
delay(2000); // Delay to debounce button
analogWrite(pwm1, 250);
analogWrite(pwm2, 250);
delay(2000); // Open for 2 seconds
delay(GateTimer); // Open for GateTimer milliseconds
analogWrite(pwm1, 50); // Slow down
analogWrite(pwm2, 50); // Slow down the second gate
delay(2000); // Continue slowly for 2 seconds
analogWrite(pwm1, 0); // Stop gate 1
analogWrite(pwm2, 0); // Stop gate 2
digitalWrite(OpenLed,LOW);
delay(200); // Delay to debounce button
}
}