Limit switch to stop stepper motor

Hello!

I'm trying to use a limit switch to stop a stepper motor and enable an other one. I first tryed the 'while' function but I had the error ; could not convert from 'void' to 'bool'.

Here is a little exemple of my try :

while (myMotor1->step(1640, BACKWARD, DOUBLE));

val = digitalRead(inPin);
if (val == HIGH) {
myMotor2->step(1640, BACKWARD, DOUBLE);

#SORRYIMATOTALBEGINNER

Thank you for your help!

Please read the "how to use the forum" stickies. Read #7 and #11 carefully.

while (myMotor1->step(1640, BACKWARD, DOUBLE));

This is wrong. The step() method does not return a value.

You are going about this wrong.

What you want to do is something like this:

   one: check if at limit.
           if not at limit
           {
              step ONCE
              go to one:
           }

Of course, we'll slap you silly if you actually use goto. The idea is to move one step at a time, toward the switch, while the switch is not pressed.

benjoulx:
while (myMotor1->step(1640, BACKWARD, DOUBLE));

How come this is almost identical to this other Thread to which I have already replied - and apparently been ignored?

If the other Thread is yours under a different name please click "Report to Moderator" and ask to have it merged with this Thread.

...R

Hello Robin2. I just reported it to the moderator.

Come on, stay calm.

benjoulx:
Come on, stay calm.

I would be more calmed if I thought you had taken any notice of the Reply I gave in the other Thread.

...R

Actually I did. I just did not have time to reply yet.

Hi PaulS,

So what is the solution for not using 'goto' ?

Thank you for taking the time to answer!

So what is the solution for not using 'goto' ?

Use [functions](http://So what is the solution for not using 'goto' ?)

Thank you!