This repository has been archived by the owner on Mar 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Codigoarduinomovimiento_sinmejorar.ino.ino
101 lines (80 loc) · 2.16 KB
/
Codigoarduinomovimiento_sinmejorar.ino.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
int motor_left[] = {5, 6};
int motor_right[] = {7, 8};
int state = 0;
int ledPin=12;
// --------------------------------------------------------------------------- Setup
void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); //Declara pin de Salida
digitalWrite(ledPin, LOW); //Normalmente Apagado
// Prueba de motores
int i;
for(i = 0; i < 2; i++){
pinMode(motor_left[i], OUTPUT);
pinMode(motor_right[i], OUTPUT);
}
}
// --------------------------------------------------------------------------- Loop
void loop() {
//si el modulo a manda dato, guardarlo en estado.
if(Serial.available() > 0){
state = Serial.read();
} // esta parte del código es para solo 1 Carácter o Unidad.
// Se mueve hacia delante y led "OFF".
if (state == '0') {
digitalWrite(ledPin, HIGH);
drive_forward();
Serial.println("LED=OFF && delante");
}
// Se mueve hacia atrás y led "ON".
else
if (state == '1') {
digitalWrite(ledPin, LOW);
drive_backward();
Serial.println("LED=ON && Atrás");
}
// Se mueve hacia la derecha.
else
if (state == '2') {
turn_right();
Serial.println("Giro Derecha");
}
// Se mueve hacia la izquierda.
else
if (state == '3') {
turn_left();
Serial.println("Giro Izquierda");
}
}
// --------------------------------------------------------------------------- Drive
void motor_stop(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], LOW);
delay(25);
}
void drive_forward(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}
void drive_backward(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);
digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}
void turn_left(){
digitalWrite(motor_left[0], LOW);
digitalWrite(motor_left[1], HIGH);
digitalWrite(motor_right[0], HIGH);
digitalWrite(motor_right[1], LOW);
}
void turn_right(){
digitalWrite(motor_left[0], HIGH);
digitalWrite(motor_left[1], LOW);
digitalWrite(motor_right[0], LOW);
digitalWrite(motor_right[1], HIGH);
}