Having trouble getting the code to compile, and motor control

// constant variables
#include <Stepper.h>

const int PartsensPin = 40;                   // Part in nest Sensor
const int SolenoidAPin = 30;                  // Solenoid A Pin Right Side
const int SolASensInPin = 2;                    // Solenoid A Sensor 1
const int SolASensOutPin = 3;                   // Solenoid A Sensor 2
const int SolenoidBPin = 4;                  // Solenoid B Pin Left Side
const int SolBSensInPin = 5;                    // Solenoid B Sensor 1
const int SolBSensOutPin = 6;                   // Solenoid B Sensor 2
const int DirMoter1 = 7;                       // motor 1 Dir pin Right
const int DirMoter2 = 8;                       // motor 2 Dir pin Right
const int DirMoter3 = 9;                       // motor 3 Dir pin Left
const int DirMoter4 = 10;                      // motor 4 Dir pin left
const int EjectionSolenoid = 11;            // ejection solinoid under nest
const int PressInPin = 44;                      // press start signal
const int PressOutPin = 13;                     // send finished or empty nest signal to press
const int StepPin1 = 14;
const int StepPin2 = 15;
const int StepPin3 = 16;
const int StepPin4 = 17;
const int RsFbs = 18;                        // Right Side Front Bump Switch for signalling arm back
const int RsBbs = 19;                        // Right Side Back Bump Switch for signaling arm is back
const int LsFbs = 20;                        // Left Side Front bump switch for signaling arm back
const int LsBbs = 21;                        // Left Side Back Bump Switch for signaling arm is back
int pd = 500;                             // Pulse Delay period
int pressState = 0;                       // Variable For reading press status
int prevpressState;
const int stepsPerRevolution = 5000;   // Stepps for revolution
// initialize the stepper library on pins 7 through 10 and 14 through 17:
Stepper myStepper(stepsPerRevolution, 14, 15, 16, 17);
bool powerOn = false;
bool partisin = false;
bool PowerForward = false;
bool BackItUpp = false;
bool PowerMotor = false;
bool powerback = false;
boolean setdir = LOW;                     // Set Direction
void revmotor ()
{
  setdir = !setdir;
}
void setup()
{
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  //setup to be adjusted 13 total
  // set the speed at 60rpm:
  pinMode(PressInPin, INPUT_PULLUP);             // Press signal input
  pinMode(PartsensPin, INPUT_PULLUP);         // part in nest sensor
  pinMode(SolASensInPin, INPUT_PULLUP);          // solenoid Sensor A In
  pinMode(SolASensOutPin, INPUT_PULLUP);         // solenoid Sensor A Out
  pinMode(SolBSensInPin, INPUT_PULLUP);          // Solenoid Sensor B In
  pinMode(SolBSensOutPin, INPUT_PULLUP);         // Solenoid sensor B Out
  pinMode(RsFbs, INPUT_PULLUP);               // Right Side Front Bumper Switch
  pinMode(RsBbs, INPUT_PULLUP);               // Right Side Back Bumper Switch
  pinMode(LsFbs, INPUT);               // Left Side Front Bump Switch
  pinMode(LsBbs, INPUT);               // Left Side Back Bump Switch

  pinMode(SolenoidAPin, OUTPUT);              // solonoid A is outputting
  pinMode(SolenoidBPin, OUTPUT);              // solonoid B is outputting
  pinMode(EjectionSolenoid, OUTPUT);          // Part ejection Solenoid
  pinMode(PressOutPin, OUTPUT);                  // Output to press

  pinMode(DirMoter1, OUTPUT);                    //  arm motor 1 LEFT
  pinMode(DirMoter2, OUTPUT);                    //  Saw motor LEFT
  pinMode(DirMoter3, OUTPUT);                    //  arm motor 2 RIGHT
  pinMode(DirMoter4, OUTPUT);                    //  arm motor RIGHT
  prevpressState = digitalRead(PressInPin);
#define SPD 2000
#define SLW_DWN_SPD 3000
}
//Homing sequence

void loop()
{
  // Lock In Original State Of each Sensor
  int partsensState = digitalRead(PartsensPin);
  int solAState = digitalRead(SolASensInPin);
  int solBState = digitalRead(SolBSensInPin);
  int pressState = digitalRead(PressInPin);
  int RsFbsstate = digitalRead(RsFbs);
  int LsFbsstate = digitalRead(LsFbs);
  int RsBbsstate = digitalRead(RsBbs);
  int LsBbsstate = digitalRead(LsBbs);
  // Press Input State :
  // powerswitch state change
  if ((digitalRead(PartsensPin) == HIGH) && (digitalRead(pressState)))
  {
    //Press On
    Serial.println("Press ON");
    delay(750);
    digitalWrite(SolenoidAPin, HIGH);      // Once the press says go, it waits till the part is sensed in the nest
    digitalWrite(SolenoidBPin, HIGH);
    Serial.println(" Part Is In Nest ");
    powerOn = true;
    partisin = true;
  }
  else
  {
    //press off
    Serial.println( "Press Off" );
    delay(500);
    digitalWrite(SolenoidAPin, LOW);
    digitalWrite(SolenoidBPin, LOW);
    powerOn = false;
    Serial.print(" No Part, back to start");    //the loop, until the parts in and press says go, code will not continue
  }
  delay(25);  // debounce

  //  cutting phase
  prevpressState = pressState;
  // only check sensors if powerOn is true
  if (partisin == true)
  {
    Serial.print( "A: "); Serial.print(PartsensPin);
    Serial.print( ", B: " ); Serial.print(solAState);
    Serial.print( ", C: " ); Serial.print(solBState);
    Serial.println();
    // if all the sensors say the clamps are down and part is in nest, start the saws
    // maybe try while to loop until conditions are met individually, use bool logic to hold it, or bool to create/access diffrent
begining:  // Go through and add variations and modes, use bellow as logic puzzle
      if ((digitalRead(RsFbs) == LOW) && (digitalRead(LsFbs) == LOW) && (digitalRead(RsBbs) == HIGH) && (digitalRead(LsBbs) == HIGH))
    {
      PowerMotor = true;
      goto startloop;

    }
      else if ((digitalRead(RsFbs) == LOW) && (digitalRead(LsFbs) == LOW) && (digitalRead(RsBbs) == LOW) && (digitalRead(LsBbs) == LOW))
    {
      PowerMotor = true;
      goto SelectACut;
    }
      else if ((digitalRead(RsFbs) == HIGH) && (digitalRead(LsFbs) == HIGH))
    {
      powerback = true;
      PowerMotor = false;
      goto backup;
    }



startloop:
    myStepper.step(7200);
    Serial.println (" time to cutty");
    digitalWrite(DirMoter2, HIGH);            // set direction
    digitalWrite(DirMoter4, HIGH);
    digitalWrite(StepPin2, HIGH);
    digitalWrite(StepPin4, HIGH);
    Serial.println (" Start saws ");
    digitalWrite(StepPin1, HIGH);
    digitalWrite(StepPin3, HIGH);
    digitalWrite(DirMoter1, HIGH);                // start the cutting motion
    digitalWrite(DirMoter3, HIGH);
    Serial.println(" still cuttin ");
    goto begining;

backup:
    myStepper.step(3000);
    Serial.println("Time to reset");
    digitalWrite(StepPin2, setdir);
    digitalWrite(StepPin4, setdir);
    digitalWrite(DirMoter2, LOW);                // reverse the cutting motion
    digitalWrite(DirMoter4, LOW);
    digitalWrite(StepPin2, HIGH);           // Start the stepper Motor saws
    digitalWrite(StepPin4, HIGH);
    goto begining;

SelectACut:
    if ((digitalRead(DirMoter2) == HIGH) && (digitalRead(DirMoter4) == HIGH))
    {
      Serial.println(" Keep It Forward ");
      goto KeepItForward;
    }
    if ((digitalRead(DirMoter2) == LOW) && (digitalRead(DirMoter4) == LOW))
    {
      goto KeepBackingUp;
    }

KeepItForward:
    while ((digitalRead(RsFbs) == LOW) && (digitalRead(LsFbs) == LOW) && (digitalRead(RsBbs) == LOW) && (digitalRead(LsBbs) == LOW))
    {
      myStepper.step(7200);
      Serial.println (" time to cutty");
      digitalWrite(DirMoter2, HIGH);            // set direction
      digitalWrite(DirMoter4, HIGH);
      digitalWrite(StepPin2, HIGH);
      digitalWrite(StepPin4, HIGH);
      Serial.println (" Start saws ");
      digitalWrite(StepPin1, HIGH);
      digitalWrite(StepPin3, HIGH);
      digitalWrite(DirMoter1, HIGH);                // start the cutting motion
      digitalWrite(DirMoter3, HIGH);
      Serial.println(" still cuttin ");
    }
      delay(2500);
      PowerMotor = false;
      goto begining;
    

KeepBackingUp:
    myStepper.step(3000);
    Serial.println("Keep going Back");
    digitalWrite(StepPin2, setdir);
    digitalWrite(StepPin4, setdir);
    digitalWrite(DirMoter2, LOW);                // reverse the cutting motion
    digitalWrite(DirMoter4, LOW);
    digitalWrite(StepPin2, HIGH);           // Start the stepper Motor saws
    digitalWrite(StepPin4, HIGH);
    goto begining;
  }
}

begining: Uh-oh

I put that up to thank you all for the help. everything is working now that I added the bool logic to the goto's. But this is the final version of the operating code, I still need to add the ejection sequence but as of now, all motors are operating correctly.

jefhod:
I put that up to thank you all for the help. everything is working now that I added the bool logic to the goto's. But this is the final version of the operating code, I still need to add the ejection sequence but as of now, all motors are operating correctly.

Glad it works. I will say that the gotos made it very hard for me to follow the logic. If your code gets much more complicated it will become very difficult to debug. From what I can tell all of the labels following 'begining' can be functions since they all goto 'begining' at their conclusion.

Agreed, definitely gonna have to work on making a pretty version 2.0

#include <Stepper.h>
#include <ezButton.h> 
#define STEPS 400

int PartsensPin = 40;                   // Part in nest Sensor
int SolenoidAPin = 1;                  // Solenoid A Pin Right Side
int SolenoidBPin = 0;
int DirMoter1 = 5;                       // motor 1 Dir pin Right
int DirMoter2 = 6;                       // motor 2 Dir pin Right
int DirMoter3 = 10;                       // motor 3 Dir pin Left
int DirMoter4 = 7;                      // motor 4 Dir pin left
int EjectionSolenoid = 11;            // ejection solinoid under nest
int PressInPin = 44;                      // press start signal
int PressOutPin = 13;                     // send finished or empty nest signal to press
int StepPin1 = 14;
int StepPin2 = 15;
int StepPin3 = 16;
int StepPin4 = 17;
int RsFbs = 31;                        // Right Side Front Bump Switch for signalling arm back
int RsBbs = 30;                        // Right Side Back Bump Switch for signaling arm is back
int LsFbs = 36;                        // Left Side Front bump switch for signaling arm back
int LsBbs = 28;                        // Left Side Back Bump Switch for signaling arm is back
int pd = 400;                             // Pulse Delay period
int pressState = 0;                       // Variable For reading press status
int prevpressState;
const int stepsPerRevolution = 400;   // Stepps for revolution
// initialize the stepper library on pins 7 through 10 and 14 through 17:
Stepper myStepper (stepsPerRevolution, 14, 15, 16, 17);
boolean setdir = LOW;   // Set initial Direction
void revmotor ()
{
  setdir = !setdir;
}
void setup()
{
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  //setup to be adjusted 13 total
  // set the speed at 60rpm:
  pinMode(PressInPin, INPUT);             // Press signal input
  pinMode(PartsensPin, INPUT);         // part in nest sensor
  pinMode(RsFbs, INPUT);               // Right Side Front Bumper Switch
  pinMode(RsBbs, INPUT);               // Right Side Back Bumper Switch
  pinMode(LsFbs, INPUT);               // Left Side Front Bump Switch
  pinMode(LsBbs, INPUT);               // Left Side Back Bump Switch

  pinMode(SolenoidAPin, OUTPUT);              // solonoid A is outputting
  pinMode(EjectionSolenoid, OUTPUT);          // Part ejection Solenoid
  pinMode(PressOutPin, OUTPUT);                  // Output to press
  pinMode(DirMoter1, OUTPUT);                    //  arm motor 1 LEFT
  pinMode(DirMoter2, OUTPUT);                    //  Saw motor LEFT
  pinMode(DirMoter3, OUTPUT);                    //  arm motor 2 RIGHT
  pinMode(DirMoter4, OUTPUT);                    //  arm motor RIGHT
  pinMode(StepPin1, OUTPUT);
  pinMode(StepPin2, OUTPUT);
  pinMode(StepPin3, OUTPUT);
  pinMode(StepPin4, OUTPUT);
  prevpressState = digitalRead(PressInPin);
#define SPD 1000
#define SLW_DWN_SPD 2000
}
So


void 
loop()
{
Beggining:
if (digitalRead(PressInPin) == HIGH){
    delay(25); //debounce
    Serial.println("Press power on");
}

    else if (digitalRead(PartsensPin) == HIGH) {
    //if part is in
    Serial.println("Parts In");
    delay(25); // debounce
    digitalWrite(SolenoidAPin, HIGH);      // Once the press says go, it waits till the part is sensed in the nest
    Serial.println(" Locked And Loaded "); 
     delay(25);  // debounce
     }
    
    else (PartsensPin == HIGH);
    {
      delay(17500);
      Serial.print( "A: "); Serial.print(PartsensPin);
      Serial.print( ", B: " ); Serial.print(SolenoidAPin);
      Serial.println();
    
    // if all the sensors say the clamps are down and part is in nest, start the saws
    // maybe try while to loop until conditions are met individually, use bool logic to hold it, or bool to create/access diffrent
begining:  // Go through and add variations and modes, use bellow as logic puzzle
    Serial.print( " LSF: "); Serial.print(LsFbs);
    Serial.print( ", LSB: " ); Serial.print(LsBbs);
    Serial.print( ", RSF: " ); Serial.print(RsFbs);
    Serial.print( ", RSB: " ); Serial.print(RsBbs);
    Serial.println();

    do {
      myStepper.step(5000);
      Serial.println (" time to cutty");
      digitalWrite(DirMoter2, setdir);            // set direction
      digitalWrite(DirMoter4, setdir);
      delayMicroseconds(pd);
      digitalWrite(DirMoter2, HIGH);            // set direction
      digitalWrite(DirMoter4, HIGH);
      digitalWrite(StepPin2, HIGH);
      digitalWrite(StepPin4, HIGH);
      digitalWrite(DirMoter1, HIGH);
      digitalWrite(DirMoter3, HIGH);
      digitalWrite(StepPin1, HIGH);
      digitalWrite(StepPin3, HIGH);
      Serial.println (" Start saws ");
    } while ((digitalRead(LsFbs) == LOW) && (digitalRead(RsBbs) == LOW));
    delay(1200);
    loop;
    delay(25); //debounce
    do {
      myStepper.step(5000);
      Serial.println("Time To Go Back");
      digitalWrite(DirMoter1, LOW);
      digitalWrite(DirMoter2, LOW);                // reverse the cutting motion
      digitalWrite(DirMoter3, LOW);
      digitalWrite(DirMoter4, LOW);
      delayMicroseconds(pd);
      digitalWrite(StepPin1, LOW);
      digitalWrite(StepPin2, LOW);           // Start the stepper Motor saws
      digitalWrite(StepPin3, LOW);
      digitalWrite(StepPin4, LOW);
      Serial.println(" keep going home ");
    } while ((digitalRead(LsBbs) == LOW) && (digitalRead(RsFbs) == LOW) && (digitalRead(LsFbs) == HIGH) && (digitalRead(RsBbs) == HIGH));
    delay(50);  // debounce
    Serial.println("Ejection Time");
    delay(500);
    digitalWrite(SolenoidAPin, LOW);
    digitalWrite(SolenoidBPin, LOW);
    delay(500);
    digitalWrite(EjectionSolenoid, HIGH);
    delay(750);
    digitalWrite(EjectionSolenoid, LOW);
  }
}

  

so I’m running into what I believe is some type of formatting issue where the code is ignoring the if statement blocks and going directly into the motors running, where id like it to be able to confirm if conditions are true before it kicks the motors on and then back. any help is appreciated!

#include <Stepper.h>
#include <ezButton.h>
#define STEPS 400
int PartsensPin = 24;                   // Part in nest Sensor
int SolenoidAPin = 27;                  // Solenoid A Pin Right Side
int DirMoter1 = 33;                       // motor 1 Dir pin Right33
int DirMoter2 = 34;                       // motor 2 Dir pin Right34
int DirMoter3 = 35;                       // motor 3 Dir pin Left35
int DirMoter4 = 36;                      // motor 4 Dir pin left36
int EjectionSolenoid = 45;            // ejection solinoid under nest38
int PressInPin = 25;                      // press start signal
int PressOutPin = 13;                     // send finished or empty nest signal to press
int StepPin1 = 37;                        // make it pullup 37
int StepPin2 = 38;                        // pullup maybe on 38
int StepPin3 = 39;                        // potential pullups on 39
int StepPin4 = 40;                         // potential pullup on 40
int RsFbs = 31;                        // Right Side Front Bump Switch for signalling arm back
int RsBbs = 30;                        // Right Side Back Bump Switch for signaling arm is back
int LsFbs = 36;                        // Left Side Front bump switch for signaling arm back
int LsBbs = 28;                        // Left Side Back Bump Switch for signaling arm is back
int pd = 400;                             // Pulse Delay period
int pressState = 0;                       // Variable For reading press status
int prevpressState;
const int stepsPerRevolution = 400;   // Stepps for revolution
// initialize the stepper library on pins 7 through 10 and 14 through 17:
Stepper myStepper (stepsPerRevolution, 14, 15, 16, 17);
boolean setdir = LOW;   // Set initial Direction
void revmotor ()
{
  PartsensPin = !PartsensPin;
  PressInPin = !PressInPin;
}
void setup()
{
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  //setup to be adjusted 13 total
  // set the speed at 60rpm:
  pinMode(PressInPin, INPUT);             // Press signal input
  pinMode(PartsensPin, INPUT);         // part in nest sensor
  pinMode(RsFbs, INPUT);               // Right Side Front Bumper Switch
  pinMode(RsBbs, INPUT);               // Right Side Back Bumper Switch
  pinMode(LsFbs, INPUT);               // Left Side Front Bump Switch
  pinMode(LsBbs, INPUT);               // Left Side Back Bump Switch

  pinMode(SolenoidAPin, OUTPUT);              // solonoid A is outputting
  pinMode(EjectionSolenoid, OUTPUT);          // Part ejection Solenoid
  pinMode(PressOutPin, OUTPUT);                  // Output to press
  pinMode(DirMoter1, OUTPUT);                    //  arm motor 1 LEFT
  pinMode(DirMoter2, OUTPUT);                    //  Saw motor LEFT
  pinMode(DirMoter3, OUTPUT);                    //  arm motor 2 RIGHT
  pinMode(DirMoter4, OUTPUT);                    //  arm motor RIGHT
  pinMode(StepPin1, OUTPUT);
  pinMode(StepPin2, OUTPUT);
  pinMode(StepPin3, OUTPUT);
  pinMode(StepPin4, OUTPUT);
  prevpressState = digitalRead(PressInPin);
#define SPD 1000
#define SLW_DWN_SPD 2000
}

void loop()
{
  digitalWrite(PressInPin, LOW);
  digitalWrite(PartsensPin, LOW);
  digitalWrite(EjectionSolenoid, LOW);
  
Beggining:
Serial.print("A: "); Serial.print(PressInPin);
  Serial.print(", B: "); Serial.print(PartsensPin);
  Serial.print(", C: "); Serial.print(EjectionSolenoid);
  Serial.println();
  while (digitalRead(PressInPin) <= LOW); {
    delay(25); //debounce
    Serial.println("Press power Off");
    goto Beggining;
  }

  delay(50);
  Serial.println("Signal Recieved Going On");
  while (digitalRead(PartsensPin) == LOW); {
    delay(25);
    Serial.println("go back");
    goto Beggining;
  }
  Serial.println("Parts In");
  delay(3500);
  digitalWrite(SolenoidAPin, HIGH);      // Once the press says go, it waits till the part is sensed in the nest
  Serial.println(" Locked And Loaded ");
  delay(25);  // debounce
  if (digitalRead(PartsensPin) == HIGH);
  {
    Serial.println("about to cut");
    delay(17500);
    Serial.print( "A: "); Serial.print(PartsensPin);
    Serial.print( ", B: " ); Serial.print(SolenoidAPin);
    Serial.println();
  }
  // if all the sensors say the clamps are down and part is in nest, start the saws
  // maybe try while to loop until conditions are met individually, use bool logic to hold it, or bool to create/access diffrent
  if ((digitalRead(PartsensPin) == HIGH) && (digitalRead(SolenoidAPin) == HIGH)); {
    // Go through and add variations and modes, use bellow as logic puzzle
    //   Serial.print( " LSF: "); Serial.print(LsFbs);
    // Serial.print( ", LSB: " ); Serial.print(LsBbs);
    //Serial.print( ", RSF: " ); Serial.print(RsFbs);
    //Serial.print( ", RSB: " ); Serial.print(RsBbs);
    //Serial.println();
    do {
      myStepper.step(5000);
      Serial.println (" time to cutty");
      digitalWrite(DirMoter2, setdir);            // set direction
      digitalWrite(DirMoter4, setdir);
      delayMicroseconds(pd);
      digitalWrite(DirMoter2, HIGH);            // set direction
      digitalWrite(DirMoter4, HIGH);
      digitalWrite(StepPin2, HIGH);
      digitalWrite(StepPin4, HIGH);
      digitalWrite(DirMoter1, HIGH);
      digitalWrite(DirMoter3, HIGH);
      digitalWrite(StepPin1, HIGH);
      digitalWrite(StepPin3, HIGH);
      Serial.println (" Start saws ");
    } while ((digitalRead(LsFbs) == LOW) && (digitalRead(RsBbs) == LOW));
    delay(1200);
    delay(25); //debounce
    do {
      myStepper.step(5000);
      Serial.println("Time To Go Back");
      digitalWrite(DirMoter1, LOW);
      digitalWrite(DirMoter2, LOW);                // reverse the cutting motion
      digitalWrite(DirMoter3, LOW);
      digitalWrite(DirMoter4, LOW);
      delayMicroseconds(pd);
      digitalWrite(StepPin1, LOW);
      digitalWrite(StepPin2, LOW);           // Start the stepper Motor saws
      digitalWrite(StepPin3, LOW);
      digitalWrite(StepPin4, LOW);
      Serial.println(" keep going home ");
    } while ((digitalRead(LsBbs) == LOW) && (digitalRead(RsFbs) == LOW));
  }

  delay(50);  // debounce
  Serial.println("Ejection Time");
  delay(500);
  digitalWrite(SolenoidAPin, LOW);
  delay(500);
  digitalWrite(EjectionSolenoid, HIGH);
  delay(1750);
  digitalWrite(EjectionSolenoid, LOW);
}




Here’s an update to the current code, I was hoping the logic for the first while statement, when the "PressInPin " integer changed states it would continue on past the loop, but it instead is controlling when the code starts and stops and is stuck in its original declaration loop.

#include <Stepper.h>
#define STEPS 400
int PartsensPin = 40;                   // Part in nest Sensor
int SolenoidAPin = 32;                  // Solenoid A Pin Right Side
int DirMoter1 = 7;                       // motor 1 Dir pin Right7
int DirMoter2 = 8;                       // motor 2 Dir pin Right8
int DirMoter3 = 9;                       // motor 3 Dir pin Left9
int DirMoter4 = 10;                      // motor 4 Dir pin left10
int EjectionSolenoid = 45;            // ejection solinoid under nest38
int PressInPin = 44;                      // press start signal
int PressOutPin = 13;                     // send finished or empty nest signal to press
int StepPin1 = 14;                        // make it pullup 14
int StepPin2 = 15;                        // pullup maybe on 15
int StepPin3 = 16;                        // potential pullups on 16
int StepPin4 = 17;                         // potential pullup on 17
int RsFbs = 5;                        // Right Side Front Bump Switch for signalling arm back5
int RsBbs = 4;                        // Right Side Back Bump Switch for signaling arm is back4
int LsFbs = 3;                        // Left Side Front bump switch for signaling arm back3
int LsBbs = 2;                        // Left Side Back Bump Switch for signaling arm is back2
int pd = 400;                             // Pulse Delay period
int pressState = 0;                       // Variable For reading press status
int prevpressState;
const int stepsPerRevolution = 400;   // Stepps for revolution
// initialize the stepper library on pins 7 through 10 and 14 through 17:
Stepper myStepper (stepsPerRevolution, 14, 15, 16, 17);
bool powerOn = false;   // power waiting till press power
boolean setdir = LOW;   // Set initial Direction
void revmotor ()
{
  setdir = !setdir;
  PartsensPin = !PartsensPin;
  PressInPin = !PressInPin;
}
void setup()
{
  Serial.begin(9600); // opens serial port, sets data rate to 9600 bps
  //setup to be adjusted 13 total
  // set the speed at 60rpm:
  pinMode(PressInPin, INPUT);             // Press signal input
  pinMode(PartsensPin, INPUT);         // part in nest sensor
  pinMode(RsFbs, INPUT);               // Right Side Front Bumper Switch
  pinMode(RsBbs, INPUT);               // Right Side Back Bumper Switch
  pinMode(LsFbs, INPUT);               // Left Side Front Bump Switch
  pinMode(LsBbs, INPUT);               // Left Side Back Bump Switch

  pinMode(SolenoidAPin, OUTPUT);              // solonoid A is outputting
  pinMode(EjectionSolenoid, OUTPUT);          // Part ejection Solenoid
  pinMode(PressOutPin, OUTPUT);                  // Output to press
  pinMode(DirMoter1, OUTPUT);                    //  arm motor 1 LEFT
  pinMode(DirMoter2, OUTPUT);                    //  Saw motor LEFT
  pinMode(DirMoter3, OUTPUT);                    //  arm motor 2 RIGHT
  pinMode(DirMoter4, OUTPUT);                    //  arm motor RIGHT
  pinMode(StepPin1, OUTPUT);
  pinMode(StepPin2, OUTPUT);
  pinMode(StepPin3, OUTPUT);
  pinMode(StepPin4, OUTPUT);
  prevpressState = digitalRead(PressInPin);
#define SPD 1000
#define SLW_DWN_SPD 2000
}
void loop()
{
  // Lock In Original State Of each Sensor
  int partsensState = digitalRead(PartsensPin);
  int pressState = digitalRead(PressInPin);
  int RsFbsstate = digitalRead(RsFbs);
  int LsFbsstate = digitalRead(LsFbs);
  int RsBbsstate = digitalRead(RsBbs);
  int LsBbsstate = digitalRead(LsBbs);
  // Press Input State :
Beggining:
  if (pressState != prevpressState )
  {
    Serial.print( ", A: " ); Serial.print(PartsensPin);
    Serial.print( ", B: " ); Serial.print(SolenoidAPin);
    Serial.print( ", C: " ); Serial.print(EjectionSolenoid);
    Serial.print( ", D: " ); Serial.print(pressState);
    Serial.print( ", E: " ); Serial.print(RsFbsstate);
    Serial.print( ", F: " ); Serial.print(LsFbsstate);
    Serial.print( ", G: " ); Serial.print(RsBbsstate);
    Serial.print( ", H: " ); Serial.print(LsBbsstate);
    Serial.println();
    Serial.print(" Beginin ");
    // powerswitch state change
    if ((digitalRead(PressInPin) == HIGH) and (digitalRead(PartsensPin) == HIGH))
    {
      //Press On
      Serial.println("Press ON");
      delay(350);
      digitalWrite(SolenoidAPin, HIGH);      // Once the press says go, it waits till the part is sensed in the nest
      Serial.println(" Part Is In Nest ");
      powerOn = true;
    }
    else
    {
      //press off
      Serial.println( "Press Off" );
      delay(500);
      digitalWrite(SolenoidAPin, LOW);
      powerOn = false;
      Serial.print(" No Part, back to start");    //the loop, until the parts in and press says go, code will not continue
      goto Beggining;
    }
    delay(25);  // debounce
  }
  //  cutting phase
  prevpressState = pressState;
  // only check sensors if powerOn is true
  if (powerOn == true)
  {
    Serial.print( "A: "); Serial.print(PartsensPin);
    Serial.print( ", B: " ); Serial.print(SolenoidAPin);
    Serial.print( ", C: " ); Serial.print(EjectionSolenoid);
    Serial.print( ", D: " ); Serial.print(pressState);
    Serial.println();
    // start my cutting cycle
    if ((digitalRead(partsensState) == HIGH) && (digitalRead(SolenoidAPin) == HIGH)) {
      // Go through and add variations and modes, use bellow as logic puzzle
      //starting pulse and potential starting values
      do {
        Serial.println (" Start saws ");
        myStepper.step(5000);
        digitalWrite(DirMoter2, HIGH);            // set direction
        digitalWrite(DirMoter4, HIGH);
        digitalWrite(StepPin2, HIGH);
        digitalWrite(StepPin4, HIGH);
        digitalWrite(DirMoter1, HIGH);
        digitalWrite(DirMoter3, HIGH);
        digitalWrite(StepPin1, HIGH);
        digitalWrite(StepPin3, HIGH);
         Serial.print( ", E: " ); Serial.print(RsFbsstate);
         Serial.print( ", F: " ); Serial.print(LsFbsstate);
         Serial.print( ", G: " ); Serial.print(RsBbsstate);
         Serial.print( ", H: " ); Serial.print(LsBbsstate);
         Serial.println();

      } while ((digitalRead(LsFbsstate) == LOW) && (digitalRead(RsBbsstate) == LOW));
      //return
    
    delay(25); //debounce
    delay(4200);
    
      do {
        myStepper.step(5000);
        Serial.println("Time To Go Back");
        digitalWrite(DirMoter1, LOW);
        digitalWrite(DirMoter2, LOW);                // reverse the cutting motion
        digitalWrite(DirMoter3, LOW);
        digitalWrite(DirMoter4, LOW);
        delayMicroseconds(pd);
        digitalWrite(StepPin1, LOW);
        digitalWrite(StepPin2, LOW);           // Start the stepper Motor saws
        digitalWrite(StepPin3, LOW);
        digitalWrite(StepPin4, LOW);
        Serial.println(" keep going home ");
         Serial.print( ", E: " ); Serial.print(RsFbsstate);
         Serial.print( ", F: " ); Serial.print(LsFbsstate);
         Serial.print( ", G: " ); Serial.print(RsBbsstate);
         Serial.print( ", H: " ); Serial.print(LsBbsstate);
         Serial.println();

      } while ((digitalRead(LsBbsstate) == LOW) && (digitalRead(RsFbsstate) == LOW));
      delay(50);  // debounce
      Serial.println("Ejection Time");
      delay(500);
      digitalWrite(SolenoidAPin, LOW);
      delay(500);
      digitalWrite(EjectionSolenoid, HIGH);
      delay(1750);
      digitalWrite(EjectionSolenoid, LOW);
      Serial.print("going to da beginin");
      goto Beggining;
    }
  }
}

Above is the newest version of the code with everything Working mutch smoother

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.