Last active
March 11, 2019 21:22
-
-
Save savolla/5dc6a41a50228c0445e9f594f2d49e53 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int listOfAngles[] = {30, 45, 60, 90, 180, 360}; | |
void setup() { | |
pinMode(2, OUTPUT); | |
pinMode(3, OUTPUT); | |
pinMode(4, OUTPUT); | |
pinMode(5, OUTPUT); | |
} | |
void rotateStepperMotor(bool rotationDirection, float rotationSpeed, int angle) | |
/* | |
* This function takes three parameters and makes the stepper motor rolling :P | |
* ---- | |
* example: | |
* rotateStepperMotor(1, 50, 30) // rotates the motor 30 degrees clockwise in 50 milliseconds | |
* rotateStepperMotor(0, 1000, 95) // rotates the motor 95 degrees counter clockwise in 10 milliseconds | |
*/ | |
{ | |
float stepperMotorConstant = 15.5; | |
if ( rotationDirection == 0 ) // clockwise | |
{ | |
for (int i=0; i <= angle/stepperMotorConstant; i++) | |
{ | |
for ( int j=2;j<=5;j++) | |
{ | |
digitalWrite(j, HIGH); | |
delay(rotationSpeed); | |
digitalWrite(j, LOW); | |
} | |
} | |
} | |
else if ( rotationDirection == 1 ) // counterclockwise | |
{ | |
for (int i=0; i <= angle/stepperMotorConstant; i++) | |
{ | |
for ( int j=5;j>=2;j--) | |
{ | |
digitalWrite(j, HIGH); | |
delay(rotationSpeed); | |
digitalWrite(j, LOW); | |
} | |
} | |
} | |
} | |
void loop() | |
{ | |
int directionCounter = 2; | |
for (int i = 0; i<6; i++) | |
{ | |
rotateStepperMotor(1,10,listOfAngles[i]); | |
delay(1500); | |
} | |
rotateStepperMotor(0,20,360); | |
rotateStepperMotor(1,9,360); | |
for (int i=15; i<=360; i+=30) | |
{ | |
if ( directionCounter % 2 == 0 ) | |
{ | |
rotateStepperMotor(0,9,i); | |
} | |
else | |
{ | |
rotateStepperMotor(1,9,i); | |
} | |
delay(100); | |
directionCounter += 1; | |
} | |
//rotateStepperMotor(1,10,720); | |
//delay(2000); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment