-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotor.cpp
39 lines (33 loc) · 890 Bytes
/
motor.cpp
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
#include <Stepper.h>
const int stepsPerRevolution = 800; // Number of steps (if stepper motor)
Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11);
int k = 2071.5;
int cou = 0;
void setup()
{
myStepper.setSpeed(50); // Setting the velocity
Serial.begin(9600);
}
void loop()
{
if (Serial.available()) {
String message = Serial.readString();
if (message != "") {
while (1) {
cou += stepsPerRevolution;
myStepper.step(stepsPerRevolution);
delay(20);
if (cou == 7200)
{
Serial.print(k * (cou*0.01/200));
Serial.print(" ");
Serial.println(cou*0.01/200);
delay(500);
myStepper.step(-cou);
cou = 0;
break;
}
}
}
}
}