-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPractica_1.ino
77 lines (56 loc) · 1.4 KB
/
Practica_1.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
}
void setup() {
// set the speed at 60 rpm:
myStepper.setSpeed(60);
// initialize the serial port:
Serial.begin(9600);
}
void loop() {
// Ask for revolutions
Serial.println("===========================\nInicio del programa");
Serial.println("===========================\n");
Serial.println("Ingrese la cantidad de vueltas.");
//Read revolutions number
while (!Serial.available()) {
//Wait for user to enter data
}
//Read
float vueltas = Serial.parseFloat();
delay(20);
//Calculate steps
int pasos = calcularPasos(vueltas);
// Print steps for revolutions
Serial.print("Ha seleccionado ");
Serial.print(vueltas);
Serial.print(" vueltas.");
//Ask for CW or CCW;
Serial.print("\nColoque 1 para CW y 2 para CCW.\n");
//Read CW or CCW
while (!Serial.available()) {
//Wait for user to enter data
}
//Read
float CW = Serial.parseFloat();
delay(20);
if (CW == 1) {
pasos_a_realizar = pasos;
}
if (CW == 2) {
pasos_a_realizar = -pasos;
}
//Mover stepper
Serial.print("Moviendo el stepper ");
Serial.print(vueltas);
Serial.print(" vueltas en direccion ");
if (pasos > 0) {
Serial.print("CCW");
}
if (pasos < 0) {
Serial.print("CW");
}
Serial.println("...");
myStepper.step(pasos_a_realizar);
delay(20);
Serial.println("\nEl movimiento ha terminado.");
Serial.println("\nReiniciando el programa...\n");
}