Motor Does not Stop - or how to stop motor

Adafruit Ethernet, Motor, Proto, Wave, Datalogger, GPS Shields - etc!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
eholz1
 
Posts: 16
Joined: Mon Jun 09, 2014 3:40 pm

Motor Does not Stop - or how to stop motor

Post by eholz1 »

Hello Forum Members,
I have an adafruit motor shield v2 motor kit.
the sample code works fine. my goal is to start the motor turning, have it run until it hits
a limit switch, and then stops turning.
I have not yet figured out how to do this - the code I have to "stop" the motor does not run while the motor
is turning, It runs only after the motor stops.

I am using the LCD with its buttons, etc.
and the following function to "release" the motor:
void ReleaseMotor() {
Serial.println("Motor Released");
myMotor->step(0,BRAKE,RELEASE);
myMotor->release();
limitButtonPin2State = 1;
}

in the void loop I use the following code to move the motor
myMotor->step(1700, FORWARD, DOUBLE);

the motor starts in the void loop, and the void loop
is supposed to detect the limit switch state change, and go out of
the loop by a call to ReleaseMotor().

I am just starting to use the motor, and code,
what am I missing.
I can post all the code if required.
Thanks,
Eric

User avatar
adafruit_support_bill
 
Posts: 88141
Joined: Sat Feb 07, 2009 10:11 am

Re: Motor Does not Stop - or how to stop motor

Post by adafruit_support_bill »

If you tell the motor to step 1700 steps, it will step 1700 steps before looking at the next command. If you want to step until you reach a limit switch, you need to step one step at a time and check the limit switch after each step.

eholz1
 
Posts: 16
Joined: Mon Jun 09, 2014 3:40 pm

Re: Motor Does not Stop - or how to stop motor

Post by eholz1 »

Thanks for the notice here, now I am still a beginner, but smarter!

Eric

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Shields from Adafruit”