Hi There,
I'm trying to modify the blink without delay sketch to run my stepper motor. I'm using the easydriver board and it works fine with I have a simple loop that uses the (delay) function.
Now I'm trying to do the same but without using the delay function. I figured the code below would work. The motor does move a bit but it seems phasey. Can anyone see why this wouldn't work? The LED doesn't miss a beat. But the motor is not behaving.
/* Blink without Delay
*
* Turns on and off a light emitting diode(LED) connected to a digital
* pin, without using the delay() function. This means that other code
* can run at the same time without being interrupted by the LED code.
*
* http://www.arduino.cc/en/Tutorial/BlinkWithoutDelay
*/
int dirpin = 3;
int steppin = 5;
int ledPin = 13; // LED connected to digital pin 13
int value = LOW; // previous value of the LED
long previousMillis = 0; // will store last time LED was updated
long interval = 100; // interval at which to blink (milliseconds)
void setup()
{
pinMode(ledPin, OUTPUT); // sets the digital pin as output
pinMode(dirpin, OUTPUT);
pinMode(steppin, OUTPUT);
}
void loop()
{
// here is where you'd put code that needs to be running all the time.
// check to see if it's time to blink the LED; that is, is the difference
// between the current time and last time we blinked the LED bigger than
// the interval at which we want to blink the LED.
if (millis() - previousMillis > interval) {
previousMillis = millis(); // remember the last time we blinked the LED
// if the LED is off turn it on and vice-versa.
if (value == LOW)
value = HIGH;
else
value = LOW;
digitalWrite(ledPin, value);
digitalWrite(steppin, value);
}
}
Thanks in Advance.