/*
* STEP motor testing
*/
int o1 = 3; // red
int o2 = 5; // blue
int o3 = 6; // green
int o4 = 9; // black
int tip1 = A5; // switch 1
int tip2 = A4; // switch 2
int vr = 5; // speed
void setup() {
pinMode(o1, OUTPUT);
pinMode(o2, OUTPUT);
pinMode(o3, OUTPUT);
pinMode(o4, OUTPUT);
pinMode(tip1, INPUT);
pinMode(tip2, INPUT);
}
void loop() {
delay(250);
if (digitalRead(tip1) == LOW) // FULL STEP
{
for (int n=0;n<12;n++) // 96 steps
{
digitalWrite(o1, HIGH);
digitalWrite(o3, HIGH);
delay(vr);
digitalWrite(o1, LOW);
digitalWrite(o3, LOW);
digitalWrite(o1, HIGH);
digitalWrite(o4, HIGH);
delay(vr);
digitalWrite(o1, LOW);
digitalWrite(o4, LOW);
digitalWrite(o2, HIGH);
digitalWrite(o4, HIGH);
delay(vr);
digitalWrite(o2, LOW);
digitalWrite(o4, LOW);
digitalWrite(o2, HIGH);
digitalWrite(o3, HIGH);
delay(vr);
digitalWrite(o2, LOW);
digitalWrite(o3, LOW);
}
}
if (digitalRead(tip2) == LOW) // HALF STEP
{
for (int n=0;n<12;n++) // 96 steps or 192 half-steps
{
digitalWrite(o1, HIGH);
digitalWrite(o3, HIGH);
delay(vr);
digitalWrite(o1, LOW);
digitalWrite(o3, LOW);
digitalWrite(o1, HIGH);
delay(vr);
digitalWrite(o1, LOW);
digitalWrite(o1, HIGH);
digitalWrite(o4, HIGH);
delay(vr);
digitalWrite(o1, LOW);
digitalWrite(o4, LOW);
digitalWrite(o4, HIGH);
delay(vr);
digitalWrite(o4, LOW);
digitalWrite(o2, HIGH);
digitalWrite(o4, HIGH);
delay(vr);
digitalWrite(o2, LOW);
digitalWrite(o4, LOW);
digitalWrite(o2, HIGH);
delay(vr);
digitalWrite(o2, LOW);
digitalWrite(o2, HIGH);
digitalWrite(o3, HIGH);
delay(vr);
digitalWrite(o2, LOW);
digitalWrite(o3, LOW);
digitalWrite(o3, HIGH);
delay(vr);
digitalWrite(o3, LOW);
}
}
}