MOTOR SHIELD and ATTACHINTERRUPT

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
User avatar
williamlynn
 
Posts: 74
Joined: Fri Dec 17, 2010 5:51 pm

MOTOR SHIELD and ATTACHINTERRUPT

Post by williamlynn »

I am using the MOTOR SHIELD for a stepper motor and I want to stop the motor when pin 2 changes state.
I use the following code to move the motor in the forward direction and I want it to stop before the 2000 steps called for by using the ATTACHINTERRUPT function; but the motor runs until the end of the 2000 steps before the interrupt seems to do anything; I'm guessing that once the motor.step code is sent to the motor shield that the interrupt cannot "interrupt the process";

Any ideas welcome; is the another way to stop the motor in mid-stream????

void forward_1()
{
motor.step(2000, FORWARD, DOUBLE);
motor.release();
x = x + 1;
Serial.println("first forward");
Serial.println(x);
delay(2000);
}

adafruit
 
Posts: 12151
Joined: Thu Apr 06, 2006 4:21 pm

Re: MOTOR SHIELD and ATTACHINTERRUPT

Post by adafruit »

thats right, but you can have an interrupt that checks pin 2 and does a single step at a time

check for timer 1 tutorials

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

Return to “Arduino Shields from Adafruit”