-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstepper_motor_3-12-25-TestCode.ino
More file actions
58 lines (56 loc) · 1.63 KB
/
stepper_motor_3-12-25-TestCode.ino
File metadata and controls
58 lines (56 loc) · 1.63 KB
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
56
57
58
// Define pin connections & motor's steps per revolution
const int dirPin_thumb = 8;
const int stepPin_thumb = 9;
const int dirPin_point = 2;
const int stepPin_point = 3;
const int dirPin_fingers = 4;
const int stepPin_fingers = 5;
const int stepsPerRevolution = 1000;
int stepDelay=1000;
void setup()
{
// Declare pins as Outputs
pinMode(stepPin_thumb, OUTPUT);
pinMode(dirPin_thumb, OUTPUT);
pinMode(stepPin_point, OUTPUT);
pinMode(dirPin_point, OUTPUT);
pinMode(stepPin_fingers, OUTPUT);
pinMode(dirPin_fingers, OUTPUT);
}
void loop()
{
//clockwise
// digitalWrite(dirPin_thumb, HIGH);
// digitalWrite(dirPin_fingers, HIGH);
// digitalWrite(dirPin_point, HIGH);
// // Spin motor
// for(int x = 0; x < stepsPerRevolution; x++)
// {
// digitalWrite(stepPin_thumb, HIGH);
// digitalWrite(stepPin_point, HIGH);
// digitalWrite(stepPin_fingers, HIGH);
// delayMicroseconds(stepDelay);
// digitalWrite(stepPin_thumb, LOW);
// digitalWrite(stepPin_point, LOW);
// digitalWrite(stepPin_fingers, LOW);
// delayMicroseconds(stepDelay);
// }
// delay(1000); // Wait a second
//counterclockwise
digitalWrite(dirPin_thumb, LOW);
digitalWrite(dirPin_fingers, HIGH);
digitalWrite(dirPin_point, HIGH);
// Spin motor
for(int x = 0; x < stepsPerRevolution; x++)
{
digitalWrite(stepPin_thumb, HIGH);
digitalWrite(stepPin_point, HIGH);
digitalWrite(stepPin_fingers, HIGH);
delayMicroseconds(stepDelay);
digitalWrite(stepPin_thumb, LOW);
digitalWrite(stepPin_point, LOW);
digitalWrite(stepPin_fingers, LOW);
delayMicroseconds(stepDelay);
}
delay(1000); // Wait a second
}