Voting resources, early voting, and poll worker information - VOTE. ... Adafruit is open and shipping.
0

Setting a Home position for a stepper motor
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

Setting a Home position for a stepper motor

by Rmac on Fri Aug 12, 2011 5:26 pm

I have a Arduino UNO microcontroller with a Adafruit shield connected to a stepper motor.
I want to be able to Home the stepper to a sensor switch which I call Home in my sketch and then step to different locations from the home position.
Attached is my current program that I want to modify to the above.

Can you tell me the best way to home the stepper in my program. I would like to use the Park button to rotate the stepper until it hits the Home switch and then make this the home position and step to the other positions from there.
Thanks for your help. Rmac


Code: Select all | TOGGLE FULL SIZE
#include <buttons.h>
#include <Bounce.h>
#include <AccelStepper.h>
#include <AFMotor.h>

/*
   Four switch stepper motor Program
 
 Turns on and off digital pins connected to pin 9,10,11,13,2 as output when  pressing  pushbuttons
 (Park,Rev,Ntrl, Dr and Home ) attached to digital pins 14,15,16,17and 18
 
 The circuit:
 * Using AfaFruit shield with motor output on M3 and M4
 * pushbuttons  are attached to digital pins 14,15,16,17,qnd switch 18 +5V supply for switches. // analog pins A0,A1,A2,A3, and A4 are used as digital pins 14 through 18:
 * 10K resistors attached to digital pins 2 from ground
 
 
 */

// constants won't change. They're used here to
// set pin numbers:

const int buttonPinPark = 14;  //Setting Park button to Pin 14
const int buttonPinRev = 15;  //Setting Reverse button to Pin 15
const int buttonPinNtrl = 16;  //Setting Neutral button to Pin 16
const int buttonPinDr = 17; //Setting Drive button to Pin 17
const int buttonPinHome = 18; //Used as input for the home position on pin 18

int buttonStatePark = 0;       //Setting Park button state to off
int buttonStateRev = 0;       //Setting Reverse button state to off
int buttonStateNtrl = 0;       //Setting Neutral button state to off
int buttonStateDr = 0;       //Setting Drive button state to off
int buttonStateHome = 0;       //Setting Drive button state to off

const int Pin9 =  9;      // PIN OUTPUT NUMBER
const int Pin10 =  10;      // PIN OUTPUT NUMBER
const int Pin11 =  11;      // PIN OUTPUT NUMBER
const int Pin13 =  13;     // PIN OUTPUT NUMBER
const int Pin2 =  2;     // PIN OUTPUT NUMBER

AF_Stepper motor(200, 2);

void setup() {

  // open the serial port at 9600 bps:
  Serial.begin(9600);


  // initialize the pin as an output:
  pinMode (Pin9,OUTPUT);   
  pinMode (Pin10,OUTPUT);
  pinMode (Pin11,OUTPUT);   
  pinMode (Pin13,OUTPUT);
  pinMode (Pin2,OUTPUT);


  // initialize the pushbutton pin as an input:
  pinMode(buttonPinPark, INPUT); 
  pinMode(buttonPinRev, INPUT);
  pinMode(buttonPinNtrl, INPUT); 
  pinMode(buttonPinDr, INPUT);
   pinMode(buttonPinHome, INPUT);

  motor.setSpeed(10);  // 10 rpm 
}

void loop()

{
  // delay 10 milliseconds before the next reading:
  delay(10);

  // read the state of the Park pushbutton value:
  buttonStatePark = digitalRead(buttonPinPark);    //code for Park button
  Serial.print("Park = "); 
  Serial.println(buttonStatePark, DEC);  // print as an ASCII-encoded decimal:

  // check if the Park pushbutton is pressed.
  // if it is, the buttonStatePark is HIGH:

  if (buttonStatePark == HIGH)
  {
    // Have output on pin 9 (5 volts:
    digitalWrite (Pin9, HIGH);

    motor.step(20, FORWARD, SINGLE);

  }
  else
  {
    // Set Pin1 Off:
    digitalWrite(Pin9, LOW);
  }

  {
    // delay 10 milliseconds before the next reading:
    delay(10);

    // read the state of the Rev pushbutton value: 
    buttonStateRev = digitalRead(buttonPinRev);    //code for Rev button
    Serial.print("Rev = "); 
    Serial.println(buttonStateRev, DEC);  // print as an ASCII-encoded decimal:

    // check if the Rev pushbutton is pressed.
    // if it is, the buttonStateRev is HIGH:

    if (buttonStateRev == HIGH)
    {
      // Have output on pin 10 (5 volts:
      digitalWrite (Pin10, HIGH);

      motor.step(40, BACKWARD, SINGLE);

    }
    else
    {
      // Set Pin2 Off:
      digitalWrite(Pin10, LOW);
      {
        // delay 10 milliseconds before the next reading:
        delay(10);

        // read the state of the Ntrl pushbutton value:
        buttonStateNtrl = digitalRead(buttonPinNtrl);    //code for Ntrl button
        Serial.print("Ntrl = "); 
        Serial.println(buttonStateNtrl, DEC);  // print as an ASCII-encoded decimal:
        // check if the Ntrl pushbutton is pressed.
        // if it is, the buttonStateNtrl is HIGH:

        if (buttonStateNtrl == HIGH)
        {
          // Have output on pin 11 (5 volts:
          digitalWrite (Pin11, HIGH);

          motor.step(60, FORWARD, SINGLE);

        }
        else
        {
          // Set Pin1 Off:
          digitalWrite(Pin11, LOW);
        }

        {
          // delay 10 milliseconds before the next reading:
          delay(10);

          // read the state of the Rev pushbutton value: 
          buttonStateDr = digitalRead(buttonPinDr);    //code for Dr button
          Serial.print("Dr = "); 
          Serial.println(buttonStateDr, DEC);  // print as an ASCII-encoded decimal:

          // check if the Dr pushbutton is pressed.
          // if it is, the buttonStateDr is HIGH:

          if (buttonStateDr == HIGH)
          {
            // Have output on pin 13 (5 volts:
            digitalWrite (Pin13, HIGH);

            motor.step(80, FORWARD, SINGLE);

          }
          else
          {
            // Set Pin2 Off:
            digitalWrite(Pin13, LOW);
            {
            }
          } 
        }
      }
    }
  }
}

Rmac
 
Posts: 31
Joined: Mon Jul 25, 2011 11:32 am

Re: Setting a Home position for a stepper motor

by adafruit_support_bill on Fri Aug 12, 2011 6:24 pm

Something like this:
Code: Select all | TOGGLE FULL SIZE
   
 if (buttonStatePark == HIGH)
{
     // Have output on pin 9 (5 volts:
     digitalWrite (Pin9, HIGH);

     While (buttonStateHome != HIGH)  // step until the home limit switch is detected
     {
           motor.step(1, FORWARD, SINGLE);
     }
}

adafruit_support_bill
 
Posts: 78954
Joined: Sat Feb 07, 2009 10:11 am

Re: Setting a Home position for a stepper motor

by Rmac on Sat Aug 13, 2011 6:20 pm

I put the while statement in the code and now I get this when compiling.

While was not declared in this scope.
Rmac
 
Posts: 31
Joined: Mon Jul 25, 2011 11:32 am

Re: Setting a Home position for a stepper motor

by Rmac on Sat Aug 13, 2011 8:31 pm

I got it to compile but now the buttons don't work
Rmac
 
Posts: 31
Joined: Mon Jul 25, 2011 11:32 am

Re: Setting a Home position for a stepper motor

by Rmac on Sat Aug 13, 2011 10:09 pm

Now I have the buttons working but the
while statement
( while (buttonStateHome != HIGH); // step until the home limit switch is detected )
is not working.
The Park button keeps the motor stepping because it is not getting a signal from Pin 2
How do I connect Pin2 to the buttonstatehome command. Do i use a digitalwrite statement and if so where?
Rmac

Code: Select all | TOGGLE FULL SIZE
 if (buttonStatePark == HIGH)
  {
    // Have output on pin 9 (5 volts:
    digitalWrite (Pin9, HIGH);

    while (buttonStateHome != HIGH)
    // step until the home limit switch is detected
   
      motor.step(100, FORWARD, SINGLE);
    }
Rmac
 
Posts: 31
Joined: Mon Jul 25, 2011 11:32 am

Re: Setting a Home position for a stepper motor

by adafruit_support_bill on Sun Aug 14, 2011 5:54 am

You could use an interrupt, or just do a digital read:
Code: Select all | TOGGLE FULL SIZE
        while (digitalRead(2) != HIGH)
        {
        // step until the home limit switch is detected
       
          motor.step(100, FORWARD, SINGLE);
        }

adafruit_support_bill
 
Posts: 78954
Joined: Sat Feb 07, 2009 10:11 am

Re: Setting a Home position for a stepper motor

by Rmac on Sun Aug 14, 2011 10:01 pm

My while statements stops the Program

I have tried the while statement and it starts the stepper moving in the correct direction but it does not stop when it activated the home switch. It keeps stepping. I have added a bunch of println statements and when I use the monitor it shows the string halts when I push the Park button. No other input
gets through.
Something about my while statement stops the program.
I have to reset it to get it started again. When I push the other buttons their is no reading. Toggling the monitor on and off will get the string started again and the motor stops.

If I push the other buttons before I push the park button they work ok and the program works fine.






See Park code below.

Code: Select all | TOGGLE FULL SIZE
void loop()

{
  // delay 10 milliseconds before the next reading:
  delay(10);

  // read the state of the Park pushbutton value:
  buttonStatePark = digitalRead(buttonPinPark);    //code for Park button
  Serial.print("Park = "); 
  Serial.println(buttonStatePark, DEC);  // print as an ASCII-encoded decimal:

  // check if the Park pushbutton is pressed.
  // if it is, the buttonStatePark is HIGH:

  if (buttonStatePark == HIGH)
  {
    // Have output on pin 9 (5 volts:
    digitalWrite (Pin9, HIGH);
 // delay 10 milliseconds before the next reading:
    delay(10);

    // read the state of the Home pushbutton value: 
    buttonStateHome = digitalRead(buttonPinHome);    //code for Home button
    Serial.print("Home = "); 
    Serial.println(buttonStateHome, DEC);  // print as an ASCII-encoded decimal:
   
    while (buttonStateHome != HIGH)
    // step until the home limit switch is detected
     
    {
      motor.step(100, FORWARD, SINGLE);
    }

  }
  else
  {
    // Set Pin9 Off:
    digitalWrite(Pin9, LOW);
   
     
Rmac
 
Posts: 31
Joined: Mon Jul 25, 2011 11:32 am

Re: Setting a Home position for a stepper motor

by adafruit_support_bill on Mon Aug 15, 2011 5:58 am

I have tried the while statement and it starts the stepper moving in the correct direction but it does not stop when it activated the home switch. It keeps stepping.

You need to check the button state IN the while loop as in the code I posted previously.
If you are not reading the button state in the loop, the button state won't change and you will never get out of the loop.

adafruit_support_bill
 
Posts: 78954
Joined: Sat Feb 07, 2009 10:11 am

Re: Setting a Home position for a stepper motor

by Rmac on Tue Aug 16, 2011 7:16 pm

What would stop the while statement from executing? My sketch stops as soon as it reads the while statement. I have moved the statement around in the void loop () and have added println statements to show the stream. It always stops with the first read of the Park pin.
In the code below the while statement is before the ButtonPinPark statement and I get a monitor read of
Park=0
Home=0
and the stream stops so the stepper does not step

if I move the while statement after the
if (buttonStatePark == HIGH) I get this read
Park=1
Home=0
The stepper starts to rotate and continues to rotate because the program has halted as well as the monitor stream.
any ideas?
Thanks Rmac



Code: Select all | TOGGLE FULL SIZE
void loop()

{
  // delay 10 milliseconds before the next reading:
  delay(10);

  // read the state of the Park pushbutton value:
  buttonStatePark = digitalRead(buttonPinPark);    //code for Park button
  Serial.print("Park = "); 
  Serial.println(buttonStatePark, DEC);  // print as an ASCII-encoded decimal:


  // delay 10 milliseconds before the next reading:
  delay(10);

  // read the state of the Home pushbutton value:
  buttonStateHome = digitalRead(buttonPinHome);    //code for Park button
  Serial.print("Home = "); 
  Serial.println(buttonStateHome, DEC);  // print as an ASCII-encoded decimal:


  // check if the Park pushbutton is pressed.
  // if it is, the buttonStatePark is HIGH:

  while (buttonStateHome != HIGH);
  // step until the home limit switch is detected

  if (buttonStatePark == HIGH)
  {
    // Have output on pin 9 (5 volts:
    digitalWrite (Pin9, HIGH);

    motor.step(20, FORWARD, SINGLE);

    // read the input pin
    digitalRead(buttonStateHome);   

  }
  else
  {
    // Set Pin9 Off:
    digitalWrite(Pin9, LOW);
  }
Rmac
 
Posts: 31
Joined: Mon Jul 25, 2011 11:32 am

Re: Setting a Home position for a stepper motor

by adafruit_support_bill on Tue Aug 16, 2011 7:36 pm

Code: Select all | TOGGLE FULL SIZE
  while (buttonStateHome != HIGH);

This loop does absolutely nothing.

Code: Select all | TOGGLE FULL SIZE
if (buttonStatePark == HIGH)
  {
    // Have output on pin 9 (5 volts:
    digitalWrite (Pin9, HIGH);

    motor.step(20, FORWARD, SINGLE);

    // read the input pin
    digitalRead(buttonStateHome);   

  }

This code is reading buttonStateHome, but is conditional on buttonStatePark.

adafruit_support_bill
 
Posts: 78954
Joined: Sat Feb 07, 2009 10:11 am

Re: Setting a Home position for a stepper motor

by Rmac on Thu Aug 18, 2011 1:24 pm

Help
I am getting nowhere with this. I have changed the code to what I think you have suggested several times without results.
Not suggesting you are not correct but the bottom line is I can't get it to work.
We started this with the suggestion that I use a while statement to home my stepper motor.
The suggestion was to use the code below
Code: Select all | TOGGLE FULL SIZE
if (buttonStatePark == HIGH)
{
     // Have output on pin 9 (5 volts:
     digitalWrite (Pin9, HIGH);

     While (buttonStateHome != HIGH)  // step until the home limit switch is detected
     {
           motor.step(1, FORWARD, SINGLE);



I have tried this and it does not work. I have tried moving the code around with the while statement in different locations. What I have discovered is the while statement STOPS my program.
I have to reset it to get it going again. As soon as it reads that home is not HIGH it stops.
Any idea why my programs stops.
If not is their any other command I can use to home a stepper to a sensor switch?
Thanks Rmac
Rmac
 
Posts: 31
Joined: Mon Jul 25, 2011 11:32 am

Re: Setting a Home position for a stepper motor

by adafruit_support_bill on Thu Aug 18, 2011 3:02 pm

Once again, you need to be reading your limit switch state in the while loop or it will never change.

The second code snippet that I posted above does that. If your limit switch is still on pin2 it should work.

Code: Select all | TOGGLE FULL SIZE
            while (digitalRead(2) != HIGH)
            {
            // step until the home limit switch is detected
           
              motor.step(100, FORWARD, SINGLE);
            }

adafruit_support_bill
 
Posts: 78954
Joined: Sat Feb 07, 2009 10:11 am

Re: Setting a Home position for a stepper motor

by Rmac on Thu Aug 18, 2011 3:50 pm

Please look at the code below. I think it is as you suggested.
When I push the Park button the motor keeps stepping and the monitor stream flow stops and never starts again.
Thanks Rmac


Code: Select all | TOGGLE FULL SIZE
#include <buttons.h>
#include <Bounce.h>
#include <AccelStepper.h>
#include <AFMotor.h>

/*
   Four switch stepper motor Program
 
 Turns on and off digital pins connected to pin 9,10,11,13,2 as output when  pressing  pushbuttons
 (Park,Rev,Ntrl, Dr and Home ) attached to digital pins 14,15,16,17and 18
 
 The circuit:
 * Using AfaFruit shield with motor output on M3 and M4
 * pushbuttons  are attached to digital pins 14,15,16,17,qnd switch 18 +5V supply for switches. // analog pins A0,A1,A2,A3, and A4 are used as digital pins 14 through 18:
 * 10K resistors attached to digital pins 2 from ground
 
 
 */

// constants won't change. They're used here to
// set pin numbers:

const int buttonPinPark = 14;  //Setting Park button to Pin 14
const int buttonPinRev = 15;  //Setting Reverse button to Pin 15
const int buttonPinNtrl = 16;  //Setting Neutral button to Pin 16
const int buttonPinDr = 17; //Setting Drive button to Pin 17
const int buttonPinHome = 18; //Used as input for the home position on pin 18

int buttonStatePark = 0;       //Setting Park button state to off
int buttonStateRev = 0;       //Setting Reverse button state to off
int buttonStateNtrl = 0;       //Setting Neutral button state to off
int buttonStateDr = 0;       //Setting Drive button state to off
int buttonStateHome = 0;       //Setting Drive button state to off

const int Pin9 =  9;      // PIN OUTPUT NUMBER
const int Pin10 =  10;      // PIN OUTPUT NUMBER
const int Pin11 =  11;      // PIN OUTPUT NUMBER
const int Pin13 =  13;     // PIN OUTPUT NUMBER
const int Pin2 =  2;     // PIN OUTPUT NUMBER

AF_Stepper motor(200, 2);

void setup() {

  // open the serial port at 9600 bps:
  Serial.begin(9600);


  // initialize the pin as an output:
  pinMode (Pin9,OUTPUT);   
  pinMode (Pin10,OUTPUT);
  pinMode (Pin11,OUTPUT);   
  pinMode (Pin13,OUTPUT);
  pinMode (Pin2,OUTPUT);


  // initialize the pushbutton pin as an input:
  pinMode(buttonPinPark, INPUT); 
  pinMode(buttonPinRev, INPUT);
  pinMode(buttonPinNtrl, INPUT); 
  pinMode(buttonPinDr, INPUT);
  pinMode(buttonPinHome, INPUT);

  motor.setSpeed(10);  // 10 rpm 
}

void loop()

{
  // delay 10 milliseconds before the next reading:
  delay(10);

  // read the state of the Park pushbutton value:
  buttonStatePark = digitalRead(buttonPinPark);    //code for Park button
  Serial.print("Park = "); 
  Serial.println(buttonStatePark, DEC);  // print as an ASCII-encoded decimal:

 
     // delay 10 milliseconds before the next reading:
  delay(10);

  // read the state of the Home pushbutton value:
  buttonStateHome = digitalRead(buttonPinHome);    //code for Park button
  Serial.print("Home = "); 
  Serial.println(buttonStateHome, DEC);  // print as an ASCII-encoded decimal:


  // check if the Park pushbutton is pressed.
  // if it is, the buttonStatePark is HIGH:

  if (buttonStatePark == HIGH)
  {
    // Have output on pin 9 (5 volts:
    digitalWrite (Pin9, HIGH);
   
   while (digitalRead(2) != HIGH)
 
    // step until the home limit switch is detected
   
    motor.step(20, FORWARD, SINGLE);
   
    if (buttonStateHome == HIGH) 
    // read the input pin
    digitalWrite(Pin2,HIGH );   

  }
  else
  {
    // Set Pin9 Off:
    digitalWrite(Pin9, LOW);[/b]  }

  {
    // delay 10 milliseconds before the next reading:
    delay(10);

    // read the state of the Rev pushbutton value: 
    buttonStateRev = digitalRead(buttonPinRev);    //code for Rev button
    Serial.print("Rev = "); 
    Serial.println(buttonStateRev, DEC);  // print as an ASCII-encoded decimal:

    // check if the Rev pushbutton is pressed.
    // if it is, the buttonStateRev is HIGH:

    if (buttonStateRev == HIGH)
    {
      // Have output on pin 10 (5 volts:
      digitalWrite (Pin10, HIGH);

      motor.step(40, BACKWARD, SINGLE);

    }
    else
    {
      // Set Pin10 Off:
      digitalWrite(Pin10, LOW);
    }
    {
      // delay 10 milliseconds before the next reading:
      delay(10);

      // read the state of the Ntrl pushbutton value:
      buttonStateNtrl = digitalRead(buttonPinNtrl);    //code for Ntrl button
      Serial.print("Ntrl = "); 
      Serial.println(buttonStateNtrl, DEC);  // print as an ASCII-encoded decimal:
      // check if the Ntrl pushbutton is pressed.
      // if it is, the buttonStateNtrl is HIGH:

      if (buttonStateNtrl == HIGH)
      {
        // Have output on pin 11 (5 volts:
        digitalWrite (Pin11, HIGH);

        motor.step(60, FORWARD, SINGLE);

      }
      else
      {
        // Set Pin11 Off:
        digitalWrite(Pin11, LOW);
      }

      {
        // delay 10 milliseconds before the next reading:
        delay(10);

        // read the state of the Rev pushbutton value: 
        buttonStateDr = digitalRead(buttonPinDr);    //code for Dr button
        Serial.print("Dr = "); 
        Serial.println(buttonStateDr, DEC);  // print as an ASCII-encoded decimal:

        // check if the Dr pushbutton is pressed.
        // if it is, the buttonStateDr is HIGH:

        if (buttonStateDr == HIGH)
        {
          // Have output on pin 13 (5 volts:
          digitalWrite (Pin13, HIGH);

          motor.step(80, FORWARD, SINGLE);

        }
        else
        {
          // Set Pin13 Off:
          digitalWrite(Pin13, LOW);

        }
      }
    }
  }
}
Rmac
 
Posts: 31
Joined: Mon Jul 25, 2011 11:32 am

Re: Setting a Home position for a stepper motor

by adafruit_support_bill on Thu Aug 18, 2011 4:27 pm

Not quite:
If your limit switch is still on pin2 it should work.


Code: Select all | TOGGLE FULL SIZE
const int buttonPinHome = 18; //Used as input for the home position on pin 18


Try substituting "buttonPinHome" for the 2.

adafruit_support_bill
 
Posts: 78954
Joined: Sat Feb 07, 2009 10:11 am

Re: Setting a Home position for a stepper motor

by Rmac on Thu Aug 18, 2011 5:08 pm

Different
When I substitute the ButtonStateHome for Pin2 I get a different reaction.
Now when I push the Park button nothing happens until I push the Home switch and then the motor run the number of steps
in the command. The Home switch does not stop the motor. But at least the momitor stream resumes which it has not in the past.
Rmac

Code: Select all | TOGGLE FULL SIZE
#include <buttons.h>
#include <Bounce.h>
#include <AccelStepper.h>
#include <AFMotor.h>

/*
   Four switch stepper motor Program
 
 Turns on and off digital pins connected to pin 9,10,11,13,2 as output when  pressing  pushbuttons
 (Park,Rev,Ntrl, Dr and Home ) attached to digital pins 14,15,16,17and 18
 
 The circuit:
 * Using AfaFruit shield with motor output on M3 and M4
 * pushbuttons  are attached to digital pins 14,15,16,17,qnd switch 18 +5V supply for switches. // analog pins A0,A1,A2,A3, and A4 are used as digital pins 14 through 18:
 * 10K resistors attached to digital pins 2 from ground
 
 
 */

// constants won't change. They're used here to
// set pin numbers:

const int buttonPinPark = 14;  //Setting Park button to Pin 14
const int buttonPinRev = 15;  //Setting Reverse button to Pin 15
const int buttonPinNtrl = 16;  //Setting Neutral button to Pin 16
const int buttonPinDr = 17; //Setting Drive button to Pin 17
const int buttonPinHome = 18; //Used as input for the home position on pin 18

int buttonStatePark = 0;       //Setting Park button state to off
int buttonStateRev = 0;       //Setting Reverse button state to off
int buttonStateNtrl = 0;       //Setting Neutral button state to off
int buttonStateDr = 0;       //Setting Drive button state to off
int buttonStateHome = 0;       //Setting Drive button state to off

const int Pin9 =  9;      // PIN OUTPUT NUMBER
const int Pin10 =  10;      // PIN OUTPUT NUMBER
const int Pin11 =  11;      // PIN OUTPUT NUMBER
const int Pin13 =  13;     // PIN OUTPUT NUMBER
const int Pin2 =  2;     // PIN OUTPUT NUMBER

AF_Stepper motor(200, 2);

void setup() {

  // open the serial port at 9600 bps:
  Serial.begin(9600);


  // initialize the pin as an output:
  pinMode (Pin9,OUTPUT);   
  pinMode (Pin10,OUTPUT);
  pinMode (Pin11,OUTPUT);   
  pinMode (Pin13,OUTPUT);
  pinMode (Pin2,OUTPUT);


  // initialize the pushbutton pin as an input:
  pinMode(buttonPinPark, INPUT); 
  pinMode(buttonPinRev, INPUT);
  pinMode(buttonPinNtrl, INPUT); 
  pinMode(buttonPinDr, INPUT);
  pinMode(buttonPinHome, INPUT);

  motor.setSpeed(10);  // 10 rpm 
}

void loop()

{
  // delay 10 milliseconds before the next reading:
  delay(10);

  // read the state of the Park pushbutton value:
  buttonStatePark = digitalRead(buttonPinPark);    //code for Park button
  Serial.print("Park = "); 
  Serial.println(buttonStatePark, DEC);  // print as an ASCII-encoded decimal:

 
     // delay 10 milliseconds before the next reading:
  delay(10);

  // read the state of the Home pushbutton value:
  buttonStateHome = digitalRead(buttonPinHome);    //code for Park button
  Serial.print("Home = "); 
  Serial.println(buttonStateHome, DEC);  // print as an ASCII-encoded decimal:


  // check if the Park pushbutton is pressed.
  // if it is, the buttonStatePark is HIGH:

  if (buttonStatePark == HIGH)
  {
    // Have output on pin 9 (5 volts:
    digitalWrite (Pin9, HIGH);
   
   while (digitalRead(buttonStateHome) != HIGH)
 
    // step until the home limit switch is detected
   
    motor.step(200, FORWARD, SINGLE);
   
    if (buttonStateHome == HIGH) 
    // read the input pin
    digitalWrite(buttonStateHome,HIGH );   

  }
  else
  {
    // Set Pin9 Off:
    digitalWrite(Pin9, LOW);
  }

  {
    // delay 10 milliseconds before the next reading:
    delay(10);

    // read the state of the Rev pushbutton value: 
    buttonStateRev = digitalRead(buttonPinRev);    //code for Rev button
    Serial.print("Rev = "); 
    Serial.println(buttonStateRev, DEC);  // print as an ASCII-encoded decimal:

    // check if the Rev pushbutton is pressed.
    // if it is, the buttonStateRev is HIGH:

    if (buttonStateRev == HIGH)
    {
      // Have output on pin 10 (5 volts:
      digitalWrite (Pin10, HIGH);

      motor.step(40, BACKWARD, SINGLE);

    }
    else
    {
      // Set Pin10 Off:
      digitalWrite(Pin10, LOW);
    }
    {
      // delay 10 milliseconds before the next reading:
      delay(10);

      // read the state of the Ntrl pushbutton value:
      buttonStateNtrl = digitalRead(buttonPinNtrl);    //code for Ntrl button
      Serial.print("Ntrl = "); 
      Serial.println(buttonStateNtrl, DEC);  // print as an ASCII-encoded decimal:
      // check if the Ntrl pushbutton is pressed.
      // if it is, the buttonStateNtrl is HIGH:

      if (buttonStateNtrl == HIGH)
      {
        // Have output on pin 11 (5 volts:
        digitalWrite (Pin11, HIGH);

        motor.step(60, FORWARD, SINGLE);

      }
      else
      {
        // Set Pin11 Off:
        digitalWrite(Pin11, LOW);
      }

      {
        // delay 10 milliseconds before the next reading:
        delay(10);

        // read the state of the Rev pushbutton value: 
        buttonStateDr = digitalRead(buttonPinDr);    //code for Dr button
        Serial.print("Dr = "); 
        Serial.println(buttonStateDr, DEC);  // print as an ASCII-encoded decimal:

        // check if the Dr pushbutton is pressed.
        // if it is, the buttonStateDr is HIGH:

        if (buttonStateDr == HIGH)
        {
          // Have output on pin 13 (5 volts:
          digitalWrite (Pin13, HIGH);

          motor.step(80, FORWARD, SINGLE);

        }
        else
        {
          // Set Pin13 Off:
          digitalWrite(Pin13, LOW);

        }
      }
    }
  }
}
Rmac
 
Posts: 31
Joined: Mon Jul 25, 2011 11:32 am

Please be positive and constructive with your questions and comments.