#define dirPin 2
#define stepPin 3
#define stepPerRev 200
int DIR, CW = HIGH, CC = LOW, DEL, STEPS = 200, count;
void setup() {
pinMode(stepPin, OUTPUT);
pinMode(dirPin, OUTPUT);
}
void step(int dir, int del) { // direction and 1/2 pulsewidth
digitalWrite(dirPin, dir);
for (int i = 0; i < stepPerRev; i++) {
digitalWrite(stepPin, HIGH);
delayMicroseconds(del);
digitalWrite(stepPin, LOW);
delayMicroseconds(del);
}
}
void loop() {
if (count == 4) // spin motor four times
count = 0;
switch (count) {
case 0: DIR = CW; DELAY = 3000; break;
case 1: DIR = CC; DELAY = 2000; break;
case 2: DIR = CW; DELAY = 1000; break;
case 3: DIR = CC; DELAY = 500; break;
default: break;
}
step(DIR, DELAY);
count++;
delay(500);
}