/* Arduino Power Magnetic Driver Board for Stepper Motors https://www.bristolwatch.com/ele4/ard_stepper.htm by Lewis Loflin lewis@bvu.net */ /* Hall sensor on Airpax blue supply, brown grnd, gray signal stepper motor demo for pf35t-48 and 55mod48 and airpax Q1 - Black Q2 - Brown Q3 - Orange Q4 - Yellow In this example we are using Digital pins 9,10,11, 12 with Q1 = digital pin 9. */ #define CW 2 #define CCW 3 //Using Meneba 23LM-304-26 #define black 9 // Q1 - Green stripe #define brown 10 // Q2 - Green #define orange 11 // Q3 - Red #define yellow 12 // Q4 - Red Stripe void setup() { // Serial.begin(9600); DDRB = 0x3f; // Digital pins 8-13 output pinMode(CW, INPUT); pinMode(CCW, INPUT); digitalWrite(CW, 1); digitalWrite(CCW, 1); PORTB = PORTB & B11100001; // all outputs to stepper off } void loop() { forward(46, 10); delay(1000); reverse(46, 10); delay(1000); forward(200, 10); delay(1000); reverse(200, 10); delay(1000); } // end loop void forward(int count, int j) { int i = 0; j = j + 5; while (1) { // digitalWrite(black, 1); // digitalWrite(brown, 0); // digitalWrite(orange, 1); // digitalWrite(yellow, 0); PORTB = PORTB & B11100001; // all outputs to stepper off PORTB = PORTB | B11101011; // OR new value delay(j); i++; if (i >= count) break; // digitalWrite(black, 0); // digitalWrite(brown, 1); // digitalWrite(orange, 1); // digitalWrite(yellow, 0); PORTB = PORTB & B11100001; // all outputs to stepper off PORTB = PORTB | B11101101; // OR new value delay(j); i++; if (i >= count) break; // digitalWrite(black, 0); // digitalWrite(brown, 1); // digitalWrite(orange, 0); // digitalWrite(yellow, 1); PORTB = PORTB & B11100001; // all outputs to stepper off PORTB = PORTB | B11110100; // OR new value delay(j); i++; if (i >= count) break; // digitalWrite(black, 1); // digitalWrite(brown, 0); // digitalWrite(orange, 0); // digitalWrite(yellow, 1); PORTB = PORTB & B11100001; // all outputs to stepper off PORTB = PORTB | B11110011; // OR new value delay(j); i++; if (i >= count) break; } PORTB = PORTB & B11100001; // all outputs to stepper off } ////////////////////////////////////////// void reverse(int count, int j) { int i = 0; j = j + 5; while (1) { // digitalWrite(black, 1); // digitalWrite(brown, 0); // digitalWrite(orange, 0); // digitalWrite(yellow, 1); PORTB = PORTB & B11100001; // all outputs to stepper off PORTB = PORTB | B11110011; // OR new value delay(j); i++; if (i >= count) break; // digitalWrite(black, 0); // digitalWrite(brown, 1); // digitalWrite(orange, 0); // digitalWrite(yellow, 1); PORTB = PORTB & B11100001; // all outputs to stepper off PORTB = PORTB | B11110101; // OR new value delay(j); i++; if (i >= count) break; // digitalWrite(black, 0); // digitalWrite(brown, 1); // digitalWrite(orange, 1); // digitalWrite(yellow, 0); PORTB = PORTB & B11100001; // all outputs to stepper off PORTB = PORTB | B11101101; // OR new value delay(j); i++; if (i >= count) break; // digitalWrite(black, 1); // digitalWrite(brown, 0); // digitalWrite(orange, 1); // digitalWrite(yellow, 0); PORTB = PORTB & B11100001; // all outputs to stepper off PORTB = PORTB | B11101011; // OR new value delay(j); i++; if (i >= count) break; } PORTB = PORTB & B11100001; // all outputs to stepper off }