void setup()
{
pinMode(6, OUTPUT); //Enable
pinMode(5, OUTPUT); //Step
pinMode(4, OUTPUT); //Direction //HIGH = CC / LOW = Clockwise
digitalWrite(6, LOW);//LOW is Enable - if this is high the motor will be disabled
setMotorDirection(true); //clockwise
}
int numsteps = 0;
int inc = 1;
void loop()
{
// Can also add in a for loop
doMotorStep(); //just turn continuously
numsteps = numsteps+inc;
if(numsteps == 5000){
setMotorDirection(false);
inc = -1;
}
if(numsteps == 0){
setMotorDirection(true);
inc = 1;
}
}
//Pin 4 is Direction
void setMotorDirection(bool clockwise)
{
delay(500);//ms
if (clockwise) {
digitalWrite(4, HIGH);//clockwise - LOW for 2208 / HIGH for 4988
} else {
digitalWrite(4, LOW);//counter clockwise - HIGH for 2208 / LOW for 4988
}
digitalWrite(6, LOW);//Enable - Pin 6 is Enable/Disable
delay(500);//ms
}
//Pin 5 is Step
//Does one step in the currently set direction
void doMotorStep()
{
digitalWrite(5, HIGH);
delayMicroseconds(450); //lower = faster, but louder
digitalWrite(5, LOW);
delayMicroseconds(450);
}