-
Notifications
You must be signed in to change notification settings - Fork 0
/
Motor_brazo.cpp
54 lines (44 loc) · 913 Bytes
/
Motor_brazo.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
40
41
42
43
44
45
46
47
48
49
50
51
//
//
//
#include "Motor_brazo.h"
#include "PID.h"
void Motor_brazoClass::inicializar(int rEN, int lEN, int rPWM, int lPWM)
{
r_en = rEN;
l_en = lEN;
l_pwm = rPWM;
r_pwm = lPWM;
pinMode(r_en, OUTPUT);
pinMode(l_en, OUTPUT);
digitalWrite(r_en, HIGH);
digitalWrite(l_en, HIGH);
pinMode(l_pwm, OUTPUT);
pinMode(r_pwm, OUTPUT);
}
void Motor_brazoClass::ajustar_velocidad(char direccion, int velocidad)
{
digitalWrite(l_en, HIGH);
digitalWrite(r_en, HIGH);
if (direccion == 'r') {
analogWrite(r_pwm, 0);
analogWrite(l_pwm, ((int)velocidad));
}
else if (direccion == 'l') {
analogWrite(l_pwm, 1);
analogWrite(r_pwm, ((int)velocidad));
}
}
void Motor_brazoClass::velocidad(int velocidad)
{
if (velocidad > 0) {
ajustar_velocidad('r', velocidad);
}
else if (velocidad < 0) {
ajustar_velocidad('l', -velocidad);
}
else {
analogWrite(l_pwm, 0);
analogWrite(r_pwm, 0);
}
}