0% found this document useful (0 votes)
13 views

Final Code Motherfucker

This document defines pin assignments and functions for controlling relays and sensors on an Arduino board. It assigns pin numbers to variables for four relays, a buzzer, and several input buttons. The setup function defines the pins as inputs or outputs. Functions are created to control sequences like feeding, covering, compressing, and more by activating the appropriate relays for set time periods. Interrupts and flags track the states of input buttons and processes.

Uploaded by

marinelascribd
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Final Code Motherfucker

This document defines pin assignments and functions for controlling relays and sensors on an Arduino board. It assigns pin numbers to variables for four relays, a buzzer, and several input buttons. The setup function defines the pins as inputs or outputs. Functions are created to control sequences like feeding, covering, compressing, and more by activating the appropriate relays for set time periods. Interrupts and flags track the states of input buttons and processes.

Uploaded by

marinelascribd
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

// Assign Arduino pin numbers to variables

#define RELAY1 9

#define RELAY2 10

#define RELAY3 11

#define RELAY4 12

#define BUZZER 8

#define LOOP 7

#define RESET 6

#define LIMIT 3

#define STOP 2

boolean stop = LOW;

volatile int autoloop = LOW;

volatile int killswitch = LOW;

volatile int coverflag = 0;

volatile int loopbtnval = HIGH;

volatile int relay1flag = LOW;

volatile int relay2flag = LOW;


volatile int relay3flag = LOW;

volatile int relay4flag = LOW;

void setup()

// Setup codes that will run once at the beginning of the program

// Assign variables as input or output

pinMode(RELAY1, OUTPUT);

pinMode(RELAY2, OUTPUT);

pinMode(RELAY3, OUTPUT);

pinMode(RELAY4, OUTPUT);

pinMode(BUZZER, OUTPUT);

pinMode(LOOP, INPUT);

pinMode(STOP, INPUT);

pinMode(RESET, INPUT);

attachInterrupt(digitalPinToInterrupt(STOP), OFF, LOW); // Stop


button is normally close
attachInterrupt(digitalPinToInterrupt(LIMIT), COVERLIMIT, HIGH); //
Limit button is normally close but initial state is open

pinMode(13, OUTPUT);

digitalWrite(RELAY1, HIGH); // Deactivate Relay 1

digitalWrite(RELAY2, HIGH); // Deactivate Relay 2

digitalWrite(RELAY3, HIGH); // Deactivate Relay 3

digitalWrite(RELAY4, HIGH); // Deactivate Relay 4

void loop()

while(stop==LOW)

// Loop codes that will run repeatedly

int loopbtnval = digitalRead(LOOP); // Read and save the value of


the pin to the variable

if(loopbtnval==LOW)

if (relay1flag==LOW && relay2flag==LOW && relay3flag==LOW &&


relay4flag==LOW) // Check if button is not pressed mid-process

autoloop=HIGH;
}

else

autoloop=LOW;

if (autoloop==HIGH && killswitch==LOW) // Loop button is normally close.


Check if circuit is open then execute code.

ZERO();

FEED();

UNCOVER();

COVER();

if(coverflag==3) // Check if limiting switch is in


final position

COMPRESS();

RECOIL();

UNCOVER();

EXTRACT();

}
int resetbtnval = digitalRead(RESET);

if(resetbtnval==LOW)

INITIAL();

if (killswitch==HIGH)

KILL();

void buzz(unsigned char time)

// Process involved in this function is pulse width modulation

analogWrite(BUZZER,170); // Send analog signal for 170 ms to the


buzzer to activate it.

delay(time); // Wait for specified amount of time

analogWrite(BUZZER,0); // Stop analog signal to the buzzer to


deactivate it.

delay(time); // Wait for specified amount of time


}

void FEED()

// Make sure vertical hydraulic is not moving

digitalWrite(RELAY1, HIGH); // Deactivate Relay 1

digitalWrite(RELAY2, HIGH); // Deactivate Relay 2

// Proceed to feed

digitalWrite(RELAY3, LOW); // Activate normally close Relay 3


(PUSH)

relay3flag = HIGH;

delay(9700); // Wait for 10 s (time it takes for full


push out)

digitalWrite(RELAY3, HIGH); // Deactivate Relay 3

relay3flag = LOW;

void COVER()

// Make sure vertical hydraulic is not moving

digitalWrite(RELAY1, HIGH); // Deactivate Relay 1

digitalWrite(RELAY2, HIGH); // Deactivate Relay 2


// Proceed to cover

digitalWrite(RELAY3, LOW); // Activate normally close Relay 3


(PUSH)

relay3flag = HIGH;

delay(4350); // Waite for 5 s (maximum time for cover


position)

digitalWrite(RELAY3, HIGH); // Deactivate Relay 3

relay3flag = LOW;

void COMPRESS()

// Make sure horizontal hydraulic is not moving

digitalWrite(RELAY3, HIGH); // Deactivate Relay 3

digitalWrite(RELAY4, HIGH); // Deactivate Relay 4

// Proceed to compress

digitalWrite(RELAY1, LOW); // Activate normally close Relay 1 (UP)

relay1flag = HIGH;

delay(7000); // Wait for 11 s (maximum time for


compress position)

digitalWrite(RELAY1, HIGH); // Deactivate Relay 1

relay1flag = LOW;

}
void UNCOVER()

// Make sure vertical hydraulic is not moving

digitalWrite(RELAY1, HIGH); // Deactivate Relay 1

digitalWrite(RELAY2, HIGH); // Deactivate Relay 2

// Proceed to uncover

digitalWrite(RELAY4, LOW); // Activate Relay 4 (PULL)

relay4flag = HIGH;

delay(8500); // Wait 10 s

digitalWrite(RELAY4, HIGH); // Deactivate Relay 4

relay4flag = LOW;

void EXTRACT()

// Make sure horizontal hydraulic is not moving

digitalWrite(RELAY3, HIGH); // Deactivate Relay 3

digitalWrite(RELAY4, HIGH); // Deactivate Relay 4

// Proceed to extract

digitalWrite(RELAY1, LOW); // Activate normally close Relay 1 (UP)

relay1flag = HIGH;

delay(13500); // Wait 20 s (maximum time for extract


position)
digitalWrite(RELAY1, HIGH); // Deactivate Relay 1

relay1flag = LOW;

void ZERO()

//

digitalWrite(RELAY2, LOW); // Activate normally close Relay 2


(DOWN)

relay2flag = HIGH;

delay(11700); // Wait 10 s (maximum time for extract


position)

digitalWrite(RELAY2, HIGH); // Deactivate Relay 2

relay2flag = LOW;

void OFF()

digitalWrite(13, HIGH);

killswitch=HIGH;

void COVERLIMIT()

coverflag+=1;

}
void RECOIL()

//

digitalWrite(RELAY2, LOW); // Activate normally close Relay 2


(DOWN)

relay2flag = HIGH;

delay(3000); // Wait 10 s (maximum time for extract


position)

digitalWrite(RELAY2, HIGH); // Deactivate Relay 2

relay2flag = LOW;

void KILL()

stop = HIGH;

digitalWrite(RELAY1, HIGH); // Deactivate Relay 1

digitalWrite(RELAY2, HIGH); // Deactivate Relay 2

digitalWrite(RELAY3, HIGH); // Deactivate Relay 3

digitalWrite(RELAY4, HIGH); // Deactivate Relay 4

void INITIAL()

// Make sure vertical hydraulic is not moving

digitalWrite(RELAY1, HIGH); // Deactivate Relay 1


digitalWrite(RELAY2, HIGH); // Deactivate Relay 2

// Proceed to uncover

digitalWrite(RELAY4, LOW); // Activate Relay 4 (PULL)

relay4flag = HIGH;

delay(8500); // Wait 10 s

digitalWrite(RELAY4, HIGH); // Deactivate Relay 4

relay4flag = LOW;

// Make sure horizontal hydraulic is not moving

digitalWrite(RELAY3, HIGH); // Deactivate Relay 3

digitalWrite(RELAY4, HIGH); // Deactivate Relay 4

// Proceed to extract

digitalWrite(RELAY1, LOW); // Activate normally close Relay 1 (UP)

relay1flag = HIGH;

delay(15000); // Wait 20 s (maximum time for extract


position)

digitalWrite(RELAY1, HIGH); // Deactivate Relay 1

relay1flag = LOW;

You might also like