granteeric

Untitled

May 12th, 2022 (edited)
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #define TIME_ANTI_REBOND      250
  2.  
  3. const int button1Pin = 2; //input pin for program 1 (223rem)
  4. const int button2Pin = 3; //input pin for program 2 (308win)
  5. const int button3Pin = 4; //input pin for program 3 (45-70gov)
  6. const int heatPin = 5; //output pin to turn on zvs induction board
  7. const int caseDropPin = 6; //output to case drop solenoid
  8. const int feederDirPin = 7; //case feeder stepper direction
  9. const int feederStepPin = 8; //case feeder stepper movement
  10. const int homeSwitch = 9; // home switch for case shelf stepper motor
  11. const int stepPin = 10; // pin to driver a4988
  12. const int dirPin = 11; // pin to driver a4988
  13. const int height1 = 12; //platform height program 1
  14. //PIN 13 NOT USED
  15. const int height2 = 14; //platform height program2
  16. const int height3 = 15; //platform height program3
  17. const int feederHomeSwitch = 16; //case feeder wheel home
  18. uint16_t heatTime1 = 6000; //heating time for program 1
  19. uint16_t heatTime2 = 8000; //heating time for program 2
  20. uint16_t heatTime3 = 7000; //heating time for program 3
  21. uint16_t loadTime = 2000; //only used if case sensor is not used allows case load before next heat cycle
  22. uint16_t caseDropTime = 500; //solenoid active time
  23. //int heatdelaystart=0;//wait for case to stabilize
  24.  
  25.  
  26. int btn1_pressed = 0;
  27. int height1_pressed = 0;
  28.  
  29. unsigned long timeBtn1 = 0;
  30. unsigned long timeHeight1 = 0;
  31.  
  32.  
  33.  
  34. void feeder(){
  35.   digitalWrite(dirPin, LOW);
  36.   digitalWrite(stepPin, HIGH);
  37.   delayMicroseconds(1000);
  38.   digitalWrite(stepPin, LOW);
  39.   delayMicroseconds(1000);
  40. }
  41.  
  42.  
  43.  
  44. void feederHome(){
  45.   while (!digitalRead(feederHomeSwitch)) //wire pin 16 to switch com and N/C to ground
  46.   {
  47.     digitalWrite(feederDirPin, HIGH);
  48.     digitalWrite(feederStepPin, HIGH);
  49.     delayMicroseconds(1000);
  50.     digitalWrite(feederStepPin, LOW);
  51.     delayMicroseconds(1000);
  52.   }
  53. }
  54.  
  55.  void shelfHome(){
  56.     while (!digitalRead(homeSwitch)) //wire pin 9 to switch com and N/C to ground
  57.   {
  58.     digitalWrite(dirPin, HIGH);
  59.     digitalWrite(stepPin, HIGH);
  60.     delayMicroseconds(1000);
  61.     digitalWrite(stepPin, LOW);
  62.     delayMicroseconds(1000);
  63.   }
  64. }
  65.  
  66.  
  67. void setup()
  68. {
  69.   //define digital inputs and outputs
  70.   pinMode(heatPin, OUTPUT);
  71.   pinMode(button1Pin, INPUT_PULLUP);
  72.   pinMode(button2Pin, INPUT_PULLUP);
  73.   pinMode(button3Pin, INPUT_PULLUP);
  74.   pinMode(caseDropPin, OUTPUT);
  75.   pinMode(homeSwitch, INPUT_PULLUP);
  76.   pinMode(stepPin, OUTPUT);
  77.   pinMode(dirPin, OUTPUT);
  78.   pinMode(height1, INPUT_PULLUP);
  79.   pinMode(height2, INPUT_PULLUP);
  80.   pinMode(height3, INPUT_PULLUP);
  81.   pinMode(feederDirPin, OUTPUT);
  82.   pinMode(feederStepPin, OUTPUT);
  83.   pinMode(feederHomeSwitch, INPUT_PULLUP);
  84.  
  85.  
  86.   //home feeder wheel
  87.  feederHome();
  88.  
  89.   //home shelf height
  90.   shelfHome();
  91. }
  92.  
  93.  
  94. void loop() {
  95.  
  96.  if( (millis() - timeBtn1) >= TIME_ANTI_REBOND && !btn1_pressed && !digitalRead(button1Pin)) {
  97.     timeBtn1=millis();
  98.     btn1_pressed=1;
  99.   }
  100.  if( (millis() - timeHeight1) >= TIME_ANTI_REBOND && !height1_pressed && !digitalRead(height1)) {
  101.    timeHeight1 = millis();
  102.    height1_pressed=1;
  103.  }
  104.  
  105.  //PROGRAM1(223Rem)
  106.  //SET PLATFORM HEIGHT  
  107.  if(btn1_pressed){
  108.    if(height1_pressed){
  109.     digitalWrite(dirPin, LOW);
  110.     digitalWrite(stepPin, HIGH);
  111.     delayMicroseconds(1000);
  112.     digitalWrite(stepPin, LOW);
  113.     delayMicroseconds(1000);
  114.  
  115.     //BEGIN PROGRAM 1 heating sequence
  116.     //Feeder feeds case to coil
  117.     for(int i=0; i<100; i++) //FEEDER TAKES 100 STEPS
  118.     {
  119.       feeder();    
  120.     }  
  121.     height1_pressed = 0;
  122.     btn1_pressed = 0;
  123.    }
  124.  }
  125.  
  126.   feederHome(); //FEEDER RETURNS TO HOME AND COLLECTS NEXT CASE
  127.   delay(loadTime);
  128.   digitalWrite(heatPin, HIGH); //turn on heating
  129.   delay(heatTime1);//heat for specified time
  130.   digitalWrite(heatPin, LOW); //turn off heating
  131.   digitalWrite(caseDropPin, HIGH); //drop case
  132.   delay(caseDropTime);//hold case drop door
  133. digitalWrite(caseDropPin, LOW); //close door
  134. }
  135.  
Add Comment
Please, Sign In to add comment