AccelStepper and limit switch

Hi All,
Here my story: I am trying to operate a valve driven by a small stepper using Uno and EasyDrive board. At the closed position the valve hits a limit switch. I am using a another switch to tell the valve to open (.i.e. motor CW) or close (i.e. motor CCW). I would like to implement the following logic: In case an open command is received the motor should turn 8000 steps to one side. In case a close command is received the motor should turn 8000 steps to the other side (-8000). Then, in case the limit switch is not activated I would like to turn an additional (-1000) steps. I would like to use AccelStepper library because I plan to operate more than one valve in parallel.
Anyhow the code without the limit switch seems to work fine, but I am not able to make the limit switch to work see below:

void loop ( )  {
  cmdVent = digitalRead (cmdPinVent); //Read the Vent Valve command to OPEN (LOW) or to CLOSE (HIGH)
   if (ventValve1.distanceToGo ( ) == 0) {
    //Check for OPEN command
    if ( cmdVent == LOW && cmdVentOld == HIGH ) {
      ventValve1.move (stepNumber);
      cmdVentOld = cmdVent;
    }
    //Check for CLOSE command
    if ( cmdVent == HIGH && cmdVentOld == LOW) {
     ventValve1.move (-stepNumber);
     cmdVentOld = cmdVent;
      switchVent1=digitalRead (switchPinVent1);
      if (switchVent1 != HIGH) {
      ventValve1.move (-1000);
      }
    }
  }
  ventValve1 .run( );
}

As I understand the AccelStepper library (and it seems I don't...) if ventValve is greater than zero the motor should run as ventValve1.run ( ) is called periodically by the main loop . Thus only when the stepper doesn't turn, i.e. when vent.distanceToGo == 0 the target of how many steps to turn should be updated per the command or per the limit switch situation.

Appreciate much your help.

Here’s an example using the AccelStepper library that moves the stepper motor back and forth based on the position variable.
It was originally 80000 but I changed to make smaller moves. You can use this example and just modify it with conditionals to control when it moves one way or the other. There are speed and acceleration variables you can modify as needed.

 //This is an example of how you would control 1 stepper

#include <AccelStepper.h>
byte ledPin = 13;
int motorSpeed = 9680; //maximum steps per second (about 3rps / at 16 microsteps)
int motorAccel = 80000; //steps/second/second to accelerate
int mposition=8000;

int motorDirPin = 7; //digital pin 7
int motorStepPin = 8; //digital pin 8

//set up the accelStepper intance
//the "1" tells it we are using a driver
AccelStepper stepper(1, motorStepPin, motorDirPin); 



void setup()
{
  stepper.setMaxSpeed(motorSpeed);
  stepper.setSpeed(motorSpeed);
  stepper.setAcceleration(motorAccel);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
  stepper.moveTo(mposition); //move 32000 steps (should be 10 rev)
}

void loop()
{
  
  //if stepper is at desired location
  if (stepper.distanceToGo() == 0)
  {
    //go the other way the same amount of steps
    //so if current position is 400 steps out, go position -400
    stepper.moveTo(-stepper.currentPosition()); 
    for (int i=0;i<4;i++)
    {
     digitalWrite(ledPin, !digitalRead(ledPin));
     delay(150);
    }
   
  }
  
  //these must be called as often as possible to ensure smooth operation
  //any delay will cause jerky motion
  stepper.run();
}

Here’s one that doesn’t use the AccelStepper library but does almost the same thing using a variable called Numberofsteps.
You can play around with that value and see the effect.

          // testing a stepper motor with a Pololu A4988 driver board or equivalent
// on an Uno the onboard led will flash with each step
// as posted on Arduino Forum at http://forum.arduino.cc/index.php?topic=208905.0

byte directionPin = 7;
byte stepPin = 8;
int numberOfSteps = 2000;
byte ledPin = 13;
int pulseWidthMicros = 20;  // microseconds
int millisbetweenSteps = 1; // milliseconds
boolean  dir= 0;

void setup() 
{ 

  Serial.begin(9600);
  Serial.println("Starting StepperTest");
  digitalWrite(ledPin, LOW);
  
  delay(2000);

  pinMode(directionPin, OUTPUT);
  pinMode(stepPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
  
 
  digitalWrite(directionPin, LOW);
              dir=0;
  
 
}
void loop() 
{ for(int n = 0; n < numberOfSteps; n++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
  }
  
  delay(3000);
  

  digitalWrite(directionPin, LOW);
  dir = 0;
  for(int n = 0; n < numberOfSteps; n++)
  {
    digitalWrite(stepPin, HIGH);
    delayMicroseconds(pulseWidthMicros);
    digitalWrite(stepPin, LOW);
    
    delay(millisbetweenSteps);
    
    digitalWrite(ledPin, !digitalRead(ledPin));
    
   }
   if (dir==0)
        {
         digitalWrite(directionPin, HIGH);
        }
         else
         if (dir=1)
         {
         digitalWrite(directionPin, LOW);
         }
}          [/   code]

Hi raschemmel,

I saw some of you previous posts and I am very grateful for your reply.
As I wrote, I am able to operate the stepper (CW or CCW) based on my command switch with the code below:

 void loop ( )  {
  cmdVent = digitalRead (cmdPinVent); //Read the Vent Valve command to OPEN (LOW) or to CLOSE (HIGH)
   if (ventValve1.distanceToGo ( ) == 0) {
    //Check for OPEN command
    if ( cmdVent == LOW && cmdVentOld == HIGH ) {
      ventValve1.move (stepNumber);
      cmdVentOld = cmdVent;
    }
    //Check for CLOSE command
    if ( cmdVent == HIGH && cmdVentOld == LOW) {
     ventValve1.move (-stepNumber);
     cmdVentOld = cmdVent;    }
  }
  ventValve1 .run( );

My problem is to introduce the condition for the limit switch into the if for the closing statement. I was trying to introduce it as follows:

      switchVent1=digitalRead (switchPinVent1);
      if (switchVent1 != HIGH) {
      ventValve1.move (-1000);
      }

Is this the way to go?

Thank you very much.

I have just realied you have two other Threads about this subject - here and here. There is a lot of common information and this is just wasting everyone's time. Please ask the Moderator to merge them all.

I had already replied on one of the other ones before I discovered this. Then when I looke up your profile I discovered another one marked SOLVED. For all I know the reply I wrote was a complete wast of time.

DON'T double and treble post.

...R

S/W is not my specialty but I'll take a look at it..
If I do, I need you to post your ENTIRE code, including any Libraries you are using (like Ventvalve ?)

Hi Robin2,

I would like please to apologize for opening the threads. Only at a later stage I realized the general forum was not the correct one and I opened the thread in the Motors and Mechanics section.
Anyhow, I am sorry if you or anyone alse wasted time. I won't happen in the future. Regarding the SOLVED thread I wrote there as there was a similar subject and I thought it is OK. Thus, I am sorry for this too. I hope you will accept my apology . :slight_smile:

Regarding the subject, I don't have yet a solution and any help is welcomed.

Wish you all a great weekend!

Morel

Please post your entire code.

Hi raschemmel,

Thank you very much for your help.
Below my entire code.
Seems that the code works (more or less…) BUT the part where I want the limit switch to make the motor to turn an additional 1000 steps. Seems I can’t make it to work.

I hope you will find a clue to the reason for this.

Thanks

#include <AccelStepper.h> //Includes the Accel stepper library

//Definition of the pins for Vent Valve 1
const int dirPinVent1 = 2; //Vent Valve  direction output pin
const int stepPinVent1 = 3; //Vent Valve steps output pin
const int switchPinVent1 = 10; //Vent Valve open / close feadback switch
const int enablePinVent1 = 8; //Vent Valve enable / disable. Setting enableVent HIGH  will put chip in disable mode
const int cmdPinVent = 6; //Vent Valve OPEN / CLOSE command. OPEN=LOW, CLOSE=HIGH

//Define variables
int speedOpenVent;  //Vent Valve OPEN speed in steps/sec
int speedCloseVent; //Vent Valve CLOSE speed in steps/sec
float resVent;  //Vent Valve resolution in mm/step
int strokeVent ; //Vent Valve stroke in mm
int stepNumber; //Calculate the number of pulses required to OPEN / CLOSE the Vent Valve
int accelVent; //Vent Valve acceleration in steps/sec^2
boolean cmdVent; //Current command for openning / closing the Vent Valves
boolean cmdVentOld; //Previous command for opening / closing the Vent Valves
boolean switchVent1; //Status of the Vent Valves open / close feadback switch. 

//Define the steppers of the Vent Valves
AccelStepper ventValve1 ( 1,stepPinVent1, dirPinVent1);

void setup ( ) {

  //Define  the Vent Valves pins and variables
  pinMode (dirPinVent1, OUTPUT);
  pinMode (stepPinVent1, OUTPUT);
  pinMode (enablePinVent1, OUTPUT);
  pinMode (cmdPinVent, INPUT_PULLUP);
  pinMode(switchPinVent1, INPUT);

  //Set speed, acceleration, resolution and stroke for the Vent Valves
  speedOpenVent = 1800; //Vent Valve OPEN speed in steps/sec
  speedCloseVent = 2000; //Vent Valve CLOSE speed in steps/sec
  accelVent = 8000; //Vent Valve acceleration in steps/sec^2
  resVent = 0.0015; //Vent Valve resolution in mm/step
  strokeVent = 12; //Vent Valve stroke in mm
  stepNumber = strokeVent/resVent; //Calculate the number of pulses required to OPEN / CLOSE the Vent Valve
  cmdVentOld = HIGH; //Assume the vent valve previous command was OPEN thus a command for CLOSING  is anticipated
  digitalWrite ( enablePinVent1, HIGH ); //Power off the motor

  Serial.begin (9600);
}

void loop ( )  {
  cmdVent = digitalRead (cmdPinVent); //Read the Vent Valve command to OPEN (LOW) or to CLOSE (HIGH)
  if (ventValve1.distanceToGo ( ) == 0) {
    digitalWrite (enablePinVent1, HIGH); //Power off the Vent Valve 1 stepper
    //Check for OPEN command
    if ( cmdVent == LOW && cmdVentOld == HIGH ) {
      ventValve1.setMaxSpeed (speedOpenVent);
      ventValve1.setAcceleration (accelVent);
      digitalWrite (enablePinVent1, LOW); //Power on the Vent Valve 1 stepper
      ventValve1.move (stepNumber);
      cmdVentOld = cmdVent;
    }
    //Check for CLOSE command
    if ( cmdVent == HIGH && cmdVentOld == LOW) {
      ventValve1.setMaxSpeed (speedCloseVent);
      ventValve1.setAcceleration (accelVent);
      digitalWrite (enablePinVent1, LOW); //Power on the Vent Valve 1 stepper
      ventValve1.move (-stepNumber);
      switchVent1=digitalRead (switchPinVent1);
      if (switchVent1 != HIGH) {
        ventValve1.move (-1000);
     }
      cmdVentOld = cmdVent;
    }
  }
  ventValve1 .run( );
}

What do I do with this ?

const int cmdPinVent = 6; //Vent Valve OPEN / CLOSE command. OPEN=LOW, CLOSE=HIGH

Do I need a momentary push button to simulate this input ?
I have a button to simulate the limit switch

Can you post a Truth Table that shows the logic states of the input pins that are not used for the driver, such as limit switch, and cmdPinVent ?

I need this information to simulate your setup without a vent valve to generate the limit switch signal
Is cmdPinVent a panel switch (OPEN/CLOSE) ? Is it a simple momentary or a toggle that toggles OPEN & closed ?

Have you tried adding debug serial print statements to see what is happening ?

BUT the part where I want the limit switch to make the motor to turn an additional 1000 steps. Seems I can't make it to work.

Are you referring to this part: ?

if (switchVent1 != HIGH)
      {
        ventValve1.move (-1000);
     }

I need your help understanding something. I told you S/W is not my specialty so you need to explain something to me,
What is the purpose of the decimal point in expressions like this one:?

 ventValve1.setMaxSpeed (speedOpenVent);

I tried to find a "seMaxSpeed" somewhere else but couldn't. Would such expressions work with an "" in place of the decimal point ? (Is the decimal point itself not special but chosen for some other reason ?
I get the fact that setMaxSpeed is a "function" of ventValve but not a C++ function since there is no function with such a name.
As far as I can tell, there would be no difference in the behaviour of the program if all the decimal points in these expressions were replaced with "
".
Is this true or am I missing something ? (I have no reason to want to replace them . I am simply trying to confirm the suspicion that they are not functionally different or significant from a "_" character. If they are, I need to know how and why .

I have the program running . When I press the cmdPinVent button the motors drive some number of steps and then stop and the Enable goes HIGH (disabling the motors). When I release the cmdPinVent button they return to their original position.
This is a start. Now I need to figure out what I need to do to try to simulate your setup, because I don't have a vent valve.
I'm not far enough in my setup to draw any conclusions but maybe this:

  if (switchVent1 != HIGH)
      {
        ventValve1.move (-1000);
     }

should include a boolean AND with "stepNumber ==0"
as in:

  if ((switchVent1 != HIGH) && (stepNumber ==0) )
      {
        ventValve1.move (-1000);
     }

That's just a guess. Maybe stepNumber is not what should be ANDed . Maybe it should be something else. Just something to think about.

morelg:
I would like please to apologize for opening the threads

Have you asked the Moderator to have them all merged?

...R

Hi raschemmel,

It is impressive to see how fast you go into my code. Just please emphasize that the functions which you may not realize where those are coming from are AccelStepper standard library functions.
Anyhow, meanwhile I was able to work on the code and arrange it in a much more readable form, see below. While doing this, I was also able to understand what I am missing. To open the valve I go stepsToOpen steps. To close the valve I would go -1.5*stepsToOpen but if I hit the limit switch I would like to stop immediately. If I won’t hit the limit switch I would like to provide an error.
Now, the only thing that I am missing is how to stop the motor based on reading the limit switch position.

#include <AccelStepper.h> //Includes the Accel stepper library

//Definition of the pins for Vent Valve 1
const int dirPinVent1 = 2; //Vent Valve  direction output pin
const int stepPinVent1 = 3; //Vent Valve steps output pin
const int switchPinVent1 = 10; //Vent Valve open / close feadback switch
const int enablePinVent1 = 8; //Vent Valve enable / disable. Setting enableVent HIGH  will put chip in disable mode
const int cmdPinVent = 6; //Vent Valve OPEN / CLOSE command. OPEN=LOW, CLOSE=HIGH

//Define variables
int speedOpenVent;  //Vent Valve OPEN speed in steps/sec
int speedCloseVent; //Vent Valve CLOSE speed in steps/sec
float resVent;  //Vent Valve resolution in mm/step
int strokeVent ; //Vent Valve stroke in mm
int stepsToOpen; //Calculate the number of pulses required to OPEN  the Vent Valve
int accelVent; //Vent Valve acceleration in steps/sec^2
boolean cmdVent; //Current command for openning / closing the Vent Valves
boolean cmdVentOld; //Previous command for opening / closing the Vent Valves
boolean switchVent1; //Status of the Vent Valves open / close feadback switch. 

//Define the steppers of the Vent Valves
AccelStepper ventValve1 ( 1,stepPinVent1, dirPinVent1);

void setup ( ) {

  //Define  the Vent Valves pins and variables
  pinMode (dirPinVent1, OUTPUT);
  pinMode (stepPinVent1, OUTPUT);
  pinMode (enablePinVent1, OUTPUT);
  pinMode (cmdPinVent, INPUT_PULLUP);
  pinMode(switchPinVent1, INPUT);

  //Set speed, acceleration, resolution and stroke for the Vent Valves
  speedOpenVent = 1800; //Vent Valve OPEN speed in steps/sec
  speedCloseVent = 2000; //Vent Valve CLOSE speed in steps/sec
  accelVent = 8000; //Vent Valve acceleration in steps/sec^2
  resVent = 0.0015; //Vent Valve resolution in mm/step
  strokeVent = 12; //Vent Valve stroke in mm
  stepsToOpen = strokeVent/resVent; //Calculate the number of pulses required to OPEN the Vent Valve
  cmdVentOld = HIGH; //Assume the vent valve previous command was OPEN thus a command for CLOSING  is anticipated
  digitalWrite ( enablePinVent1, HIGH ); //Power off the motor

  Serial.begin (9600);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                              MAIN
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop ( )  {
  //Check the command for the Vent Valves position only when the vent valves are at rest
  if (ventValve1.distanceToGo ( ) == 0) {
    digitalWrite (enablePinVent1, HIGH); //Power off the Vent Valve 1 stepper
    cmdVent = digitalRead (cmdPinVent); //Read the Vent Valve command to OPEN (LOW) or to CLOSE (HIGH)
    //Check for OPEN command
    if ( cmdVent == LOW && cmdVentOld == HIGH ) {
      openVentValves ( );
    }
    //Check for CLOSE command
    if ( cmdVent == HIGH && cmdVentOld == LOW) {
      closeVentValves ( );
    }
  }
  ventValve1.run ( );
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                     OPEN VENT VALVES FUNCTION
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void openVentValves ( ) {
  ventValve1.setMaxSpeed (speedOpenVent);
  ventValve1.setAcceleration (accelVent);
  digitalWrite (enablePinVent1, LOW); //Power on the Vent Valve 1 stepper
  ventValve1.move (stepsToOpen);
  cmdVentOld = cmdVent;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                     CLOSE VENT VALVES FUNCTION
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void closeVentValves ( ) { 
  ventValve1.setMaxSpeed (speedCloseVent);
  ventValve1.setAcceleration (accelVent);
  digitalWrite (enablePinVent1, LOW); //Power on the Vent Valve 1 stepper
  ventValve1.move (-1.5*stepsToOpen);//Move to the CLOSED (ZERO) position
//HERE I WOULD LIKE TO STOP THE MOTOR BASED ON THE switchPinVent1 STATUS
  cmdVentOld = cmdVent;
}

Maybe:

 if  (digitalRead(switchPinVent1) ==HIGH) {
ventValve1.move(0); //Stop the motor
}

But this probably won’t work since it is not in a continuous loop. Should I move it to the main loop?

Thanks :slight_smile:

Morel

Hi Robin,

I looked carefully into the "How to use this forum thread" and unfortunately I didn't find on how to contact the Moderator to merge my threads. Could you please provide a clue?

Thanks,

Morel

tried to find a "seMaxSpeed" somewhere else but couldn't. Would such expressions work with an "" in place of the decimal point ? (Is the decimal point itself not special but chosen for some other reason ?
I get the fact that setMaxSpeed is a "function" of ventValve but not a C++ function since there is no function with such a name.
As far as I can tell, there would be no difference in the behaviour of the program if all the decimal points in these expressions were replaced with "
".
Is this true or am I missing something ? (I have no reason to want to replace them . I am simply trying to confirm the suspicion that they are not functionally different or significant from a "_" character. If they are, I need to know how and why .

I believe you refer to AccelStepper classes, see AccelStepper: AccelStepper Class Reference

THANKS,

Morel

But this probably won't work since it is not in a continuous loop. Should I move it to the main loop?

Your asking me ? I've only been programming C++ since last October -early November. I have some books on C++ but I have been so busy with hardware (breadboarding circuits) that I have not taken the time to go them.

morelg:
I looked carefully into the "How to use this forum thread" and unfortunately I didn't find on how to contact the Moderator to merge my threads. Could you please provide a clue?

Just click the Report to Moderator link in any post except one of your own (which for some stupid reason won't work).

...R

Now, the only thing that I am missing is how to stop the motor based on reading the limit switch position.

I think the only way that would work is if you connect the Limit switch to pin D2 of the arduino (INT0) Pin and add an ISR that
updates the STATUS flags and disables the driver because the uC is executing the Vent valve move CLOSE command and will not execute any other instructions until it completes that one unless you use an interrupt.

Before you can do that you have to redefine this pin:

const int dirPinVent1 = 2; //Vent Valve  direction output pin

because you need pin 2 for the limit switch to pull pin -2 LOW.
The limit switch has to be pulled up with a 10k resistor on the side connected to pin -2 of the arduino.
The OTHER terminal of the limit switch should be pulled to ground with a 1 k resistor.
When the limit switch is “made” by the vent valve it connects pin -2 or the arduino with ground through the 1 k resistor.
The ISR runs and disables the motor
What happens AFTER that I don’t know but the following sketch (your code + interrupt) STOPS the motor the moment the limit switch is made if it is wired as I described. I tested it. I pressed the OPEN/CLOSE button the motor started driving. While it was moving I pressed the Limit Switch button and the motor stopped. Go figure…
All the pins in the following sketch are defined for my setup so you have to change the pin numbers and find another pin to use for dirPinVent1 so you can use pin-2 for the interrupt (Limit switch)

  #include <AccelStepper.h> //Includes the Accel stepper library

//Definition of the pins for Vent Valve 1
const int dirPinVent1 = 7; //Vent Valve  direction output pin
const int stepPinVent1 = 8; //Vent Valve steps output pin
const int enablePinVent1 = 9; //Vent Valve enable / disable. Setting enableVent HIGH  will put chip in disable mode
const int cmdPinVent = 11; //Vent Valve OPEN / CLOSE command. OPEN=LOW, CLOSE=HIGH
const int switchPinVent1 = 12; //Vent Valve open / close feadback switch

//Define variables
int speedOpenVent;  //Vent Valve OPEN speed in steps/sec
int speedCloseVent; //Vent Valve CLOSE speed in steps/sec
float resVent;  //Vent Valve resolution in mm/step
int strokeVent ; //Vent Valve stroke in mm
int stepsToOpen; //Calculate the number of pulses required to OPEN  the Vent Valve
int accelVent; //Vent Valve acceleration in steps/sec^2
boolean cmdVent; //Current command for openning / closing the Vent Valves
boolean cmdVentOld; //Previous command for opening / closing the Vent Valves
boolean switchVent1; //Status of the Vent Valves open / close feadback switch. 

//Define the steppers of the Vent Valves
AccelStepper ventValve1 ( 1,stepPinVent1, dirPinVent1);

void setup ( ) 
{

  //Define  the Vent Valves pins and variables
  pinMode (dirPinVent1, OUTPUT);
  pinMode (stepPinVent1, OUTPUT);
  pinMode (enablePinVent1, OUTPUT);
  pinMode (cmdPinVent, INPUT_PULLUP);
  pinMode(switchPinVent1, INPUT);
   attachInterrupt(0, stop, CHANGE);
  
  //Set speed, acceleration, resolution and stroke for the Vent Valves
  speedOpenVent = 1800; //Vent Valve OPEN speed in steps/sec
  speedCloseVent = 2000; //Vent Valve CLOSE speed in steps/sec
  accelVent = 8000; //Vent Valve acceleration in steps/sec^2
  resVent = 0.0015; //Vent Valve resolution in mm/step
  strokeVent = 12; //Vent Valve stroke in mm
  stepsToOpen = strokeVent/resVent; //Calculate the number of pulses required to OPEN the Vent Valve
  cmdVentOld = HIGH; //Assume the vent valve previous command was OPEN thus a command for CLOSING  is anticipated
  digitalWrite ( enablePinVent1, HIGH ); //Power off the motor

  Serial.begin (9600);
}

///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                                              MAIN
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop ( )  
{
  //Check the command for the Vent Valves position only when the vent valves are at rest
  if (ventValve1.distanceToGo ( ) == 0) 
  {
    digitalWrite (enablePinVent1, HIGH); //Power off the Vent Valve 1 stepper
    cmdVent = digitalRead (cmdPinVent); //Read the Vent Valve command to OPEN (LOW) or to CLOSE (HIGH)
    //Check for OPEN command
    if ( cmdVent == LOW && cmdVentOld == HIGH )
    {
      openVentValves ( );
    }
    //Check for CLOSE command
    if ( cmdVent == HIGH && cmdVentOld == LOW) 
    {
      closeVentValves ( );
    }
  }
  ventValve1.run ( );
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                     OPEN VENT VALVES FUNCTION
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void stop()
{
  cmdVentOld = cmdVent;
  digitalWrite (enablePinVent1, HIGH); //Power off the Vent Valve 1 stepper
}


void openVentValves ( ) 
{
  ventValve1.setMaxSpeed (speedOpenVent);
  ventValve1.setAcceleration (accelVent);
  digitalWrite (enablePinVent1, LOW); //Power on the Vent Valve 1 stepper
  ventValve1.move (stepsToOpen);
  cmdVentOld = cmdVent;
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//                                                                     CLOSE VENT VALVES FUNCTION
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void closeVentValves ( ) 
{ 
  ventValve1.setMaxSpeed (speedCloseVent);
  ventValve1.setAcceleration (accelVent);
  digitalWrite (enablePinVent1, LOW); //Power on the Vent Valve 1 stepper
  ventValve1.move (-1.5*stepsToOpen);//Move to the CLOSED (ZERO) position
  //HERE I WOULD LIKE TO STOP THE MOTOR BASED ON THE switchPinVent1 STATUS
  
  cmdVentOld = cmdVent;
}

You’ll have to figure out how to update all the status information so that the vent valve is in the correct state to open again.
The code I put in the ISR was just enough to prove that it will stop the motor. What happens AFTER that, you’ll have to straighten out.

Hi,

Thank you very much raschemmel!

I shall try and work this out and let everyone know the results.

Best,

M

What is the purpose of the decimal point in expressions like this one:?

  if (switchVent1 != HIGH)
      {
        ventValve1.move (-1000);
     }

After the declarations of Rectangle and rect, any of the public members of object rect can be accessed as if they were normal functions or normal variables, by simply inserting a dot (.) between object name and member name. This follows the same syntax as accessing the members of plain data structures. For example:

1
2
rect.set_values (3,4);
myarea = rect.area();

Found the above answer here :
http://www.cplusplus.com/doc/tutorial/classes/

Why do some of the functions or variables have a “1” at the end while the rest don’t ?

const int enablePinVent1 = 9; //Vent Valve enable / disable. Setting enableVent HIGH  will put chip in disable mode
 const int cmdPinVent = 11; //Vent Valve OPEN / CLOSE command. OPEN=LOW, CLOSE=HIGH