-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStepperMotorArduino2.ino
55 lines (46 loc) · 1.21 KB
/
StepperMotorArduino2.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// Include the AccelStepper Library
#include <AccelStepper.h>
// Define pin connections
const int dirPin = 2;
const int stepPin = 3;
// Define motor interface type
#define motorInterfaceType 1
// Creates an instance
AccelStepper myStepper(motorInterfaceType, stepPin, dirPin);
void setup() {
// set the maximum speed, acceleration factor,
// initial speed and the target position
//myStepper.setCurrentPosition(0);
myStepper.setMaxSpeed(100);
myStepper.setAcceleration(50);
myStepper.setSpeed(0);
//myStepper.moveTo(500);
Serial.begin(9600);
}
void loop() {
// Change direction once the motor reaches target position
/*
while (myStepper.distanceToGo() != 0){
myStepper.move(10);
delay(2000);
}
if (myStepper.distanceToGo() == 0){
myStepper.stop();
}
*/
// Move the motor one step
//myStepper.run();
Serial.println(myStepper.currentPosition());
zero();
Serial.println(myStepper.currentPosition());
thirty();
Serial.println(myStepper.currentPosition());
}
void zero() {
myStepper.runToNewPosition(0);
}
void thirty() {
//200 steps in a 360-degree rotation -> 1 step = 1.8 degree
//30 degrees / 1.8 = 17 steps, but unsure due to gear ratio
myStepper.runToNewPosition(17);
}