#define IN1 11 #define IN2 10 #define IN3 9 #define IN4 8 #define IN5 7 #define IN6 6 #define IN7 5 #define IN8 4 //#define FULL_ROTATION 4096 const int phases1[] = {0, 0, 0, 0, 0, 1, 1, 1}; const int phases2[] = {0, 0, 0, 1, 1, 1, 0, 0}; const int phases3[] = {0, 1, 1, 1, 0, 0, 0, 0}; const int phases4[] = {1, 1, 0, 0, 0, 0, 0, 1}; int Phase = 0; void setup() { pinMode(IN1, OUTPUT); pinMode(IN2, OUTPUT); pinMode(IN3, OUTPUT); pinMode(IN4, OUTPUT); pinMode(IN5, OUTPUT); pinMode(IN6, OUTPUT); pinMode(IN7, OUTPUT); pinMode(IN8, OUTPUT); Serial.begin(115200); } void loop() { for(int s=0; s<12; s++) { stepper(112, 2); delay(19917); } stepper(208, 1); } void stepper(int count, int motor){ int rotationDirection = 1; count *= rotationDirection; switch (motor){ case 1: for (int x = 0; x < count; x++){ digitalWrite(IN1, phases1[Phase]); digitalWrite(IN2, phases2[Phase]); digitalWrite(IN3, phases3[Phase]); digitalWrite(IN4, phases4[Phase]); IncrementPhase(rotationDirection); Serial.println(count); delay(60); } break; case 2: for (int x = 0; x < count; x++){ digitalWrite(IN5, phases1[Phase]); digitalWrite(IN6, phases2[Phase]); digitalWrite(IN7, phases3[Phase]); digitalWrite(IN8, phases4[Phase]); IncrementPhase(rotationDirection); Serial.println("motor 2"); delay(64); } break; } } void IncrementPhase(int rotationDirection) { Phase += 8; Phase += rotationDirection; Phase %= 8; }