-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodigo_msm.cpp
More file actions
37 lines (30 loc) · 846 Bytes
/
codigo_msm.cpp
File metadata and controls
37 lines (30 loc) · 846 Bytes
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
#include <Servo.h>
// Declaramos la variable para controlar el servo
Servo servoMotor;
void setup() {
// Iniciamos el monitor serie para mostrar el resultado
Serial.begin(9600);
// Iniciamos el servo para que empiece a trabajar con el pin 9
servoMotor.attach(9);
// Inicializamos al ángulo 0 el servomotor
servoMotor.write(0);
}
void loop() {
// Vamos a tener dos bucles uno para mover en sentido positivo y otro en sentido negativo
// Para el sentido positivo
for (int i = 0; i <= 180; i++)
{
// Desplazamos al ángulo correspondiente
servoMotor.write(i);
// Hacemos una pausa de 100ms
delay(100);
}
// Para el sentido negativo
for (int i = 179; i > 0; i--)
{
// Desplazamos al ángulo correspondiente
servoMotor.write(i);
// Hacemos una pausa de 100ms
delay(100);
}
}