Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define TIME_ANTI_REBOND 250
- const int button1Pin = 2; //input pin for program 1 (223rem)
- const int button2Pin = 3; //input pin for program 2 (308win)
- const int button3Pin = 4; //input pin for program 3 (45-70gov)
- const int heatPin = 5; //output pin to turn on zvs induction board
- const int caseDropPin = 6; //output to case drop solenoid
- const int feederDirPin = 7; //case feeder stepper direction
- const int feederStepPin = 8; //case feeder stepper movement
- const int homeSwitch = 9; // home switch for case shelf stepper motor
- const int stepPin = 10; // pin to driver a4988
- const int dirPin = 11; // pin to driver a4988
- const int height1 = 12; //platform height program 1
- //PIN 13 NOT USED
- const int height2 = 14; //platform height program2
- const int height3 = 15; //platform height program3
- const int feederHomeSwitch = 16; //case feeder wheel home
- uint16_t heatTime1 = 6000; //heating time for program 1
- uint16_t heatTime2 = 8000; //heating time for program 2
- uint16_t heatTime3 = 7000; //heating time for program 3
- uint16_t loadTime = 2000; //only used if case sensor is not used allows case load before next heat cycle
- uint16_t caseDropTime = 500; //solenoid active time
- //int heatdelaystart=0;//wait for case to stabilize
- int btn1_pressed = 0;
- int height1_pressed = 0;
- unsigned long timeBtn1 = 0;
- unsigned long timeHeight1 = 0;
- void feeder(){
- digitalWrite(dirPin, LOW);
- digitalWrite(stepPin, HIGH);
- delayMicroseconds(1000);
- digitalWrite(stepPin, LOW);
- delayMicroseconds(1000);
- }
- void feederHome(){
- while (!digitalRead(feederHomeSwitch)) //wire pin 16 to switch com and N/C to ground
- {
- digitalWrite(feederDirPin, HIGH);
- digitalWrite(feederStepPin, HIGH);
- delayMicroseconds(1000);
- digitalWrite(feederStepPin, LOW);
- delayMicroseconds(1000);
- }
- }
- void shelfHome(){
- while (!digitalRead(homeSwitch)) //wire pin 9 to switch com and N/C to ground
- {
- digitalWrite(dirPin, HIGH);
- digitalWrite(stepPin, HIGH);
- delayMicroseconds(1000);
- digitalWrite(stepPin, LOW);
- delayMicroseconds(1000);
- }
- }
- void setup()
- {
- //define digital inputs and outputs
- pinMode(heatPin, OUTPUT);
- pinMode(button1Pin, INPUT_PULLUP);
- pinMode(button2Pin, INPUT_PULLUP);
- pinMode(button3Pin, INPUT_PULLUP);
- pinMode(caseDropPin, OUTPUT);
- pinMode(homeSwitch, INPUT_PULLUP);
- pinMode(stepPin, OUTPUT);
- pinMode(dirPin, OUTPUT);
- pinMode(height1, INPUT_PULLUP);
- pinMode(height2, INPUT_PULLUP);
- pinMode(height3, INPUT_PULLUP);
- pinMode(feederDirPin, OUTPUT);
- pinMode(feederStepPin, OUTPUT);
- pinMode(feederHomeSwitch, INPUT_PULLUP);
- //home feeder wheel
- feederHome();
- //home shelf height
- shelfHome();
- }
- void loop() {
- if( (millis() - timeBtn1) >= TIME_ANTI_REBOND && !btn1_pressed && !digitalRead(button1Pin)) {
- timeBtn1=millis();
- btn1_pressed=1;
- }
- if( (millis() - timeHeight1) >= TIME_ANTI_REBOND && !height1_pressed && !digitalRead(height1)) {
- timeHeight1 = millis();
- height1_pressed=1;
- }
- //PROGRAM1(223Rem)
- //SET PLATFORM HEIGHT
- if(btn1_pressed){
- if(height1_pressed){
- digitalWrite(dirPin, LOW);
- digitalWrite(stepPin, HIGH);
- delayMicroseconds(1000);
- digitalWrite(stepPin, LOW);
- delayMicroseconds(1000);
- //BEGIN PROGRAM 1 heating sequence
- //Feeder feeds case to coil
- for(int i=0; i<100; i++) //FEEDER TAKES 100 STEPS
- {
- feeder();
- }
- height1_pressed = 0;
- btn1_pressed = 0;
- }
- }
- feederHome(); //FEEDER RETURNS TO HOME AND COLLECTS NEXT CASE
- delay(loadTime);
- digitalWrite(heatPin, HIGH); //turn on heating
- delay(heatTime1);//heat for specified time
- digitalWrite(heatPin, LOW); //turn off heating
- digitalWrite(caseDropPin, HIGH); //drop case
- delay(caseDropTime);//hold case drop door
- digitalWrite(caseDropPin, LOW); //close door
- }
Add Comment
Please, Sign In to add comment