-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMotor.cpp
60 lines (47 loc) · 1.28 KB
/
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <Arduino.h>
#include "Motor.h"
//
// Constructor
//
Motor::Motor(){
}
Motor::Motor(int tmpPinAvance, int tmpPinRetroceso, int tmpPinVelocidad){
pinAvance = tmpPinAvance;
pinRetroceso = tmpPinRetroceso;
pinVelocidad = tmpPinVelocidad;
pinMode(pinAvance, OUTPUT);
pinMode(pinRetroceso, OUTPUT);
pinMode(pinVelocidad, OUTPUT);
digitalWrite(pinVelocidad, HIGH);
};
//setters
void Motor::setMotor(int tmpPinAvance, int tmpPinRetroceso, int tmpPinVelocidad){
pinAvance = tmpPinAvance;
pinRetroceso = tmpPinRetroceso;
pinVelocidad = tmpPinVelocidad;
pinMode(pinAvance, OUTPUT);
pinMode(pinRetroceso, OUTPUT);
pinMode(pinVelocidad, OUTPUT);
digitalWrite(pinVelocidad, HIGH);
}
void Motor::avance(int velocidad){
digitalWrite(pinRetroceso, LOW);
digitalWrite(pinAvance, HIGH);
ajustarVelocidad(velocidad);
}
void Motor::retroceso(int velocidad){
digitalWrite(pinAvance, LOW);
digitalWrite(pinRetroceso, HIGH);
ajustarVelocidad(velocidad);
}
void Motor::paro(){
digitalWrite(pinVelocidad, 0);
digitalWrite(pinAvance, LOW);
digitalWrite(pinRetroceso, LOW);
}
void Motor::ajustarVelocidad(int velocidad){
int speedpin = map(velocidad, 0, 100, 800, 1023);
analogWrite (pinVelocidad, speedpin);
Serial.println(speedpin);
delay(50);
}