-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmotor.cpp
48 lines (40 loc) · 970 Bytes
/
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
#include "motor.h"
#include <Arduino.h>
/*
Usando el constructor
*/
Motor::Motor(int8_t pinA, int8_t pinB, int8_t pinPWM) : //no lleva tipo
pinA(pinA),
pinB(pinB),
pinPWM(pinPWM)
{
this->parar();
pinMode(this->pinA, OUTPUT);
pinMode(this->pinB, OUTPUT);
if (this->pinPWM >= 0) {
pinMode(this->pinPWM, OUTPUT);
}
}
void Motor::avanzar() {
digitalWrite(this->pinA, HIGH);
digitalWrite(this->pinB, LOW);
if (this->pinPWM >= 0) {
// digitalWrite(this->pinPWM, HIGH);
analogWrite(this->pinPWM, 255);
}
}
void Motor::retroceder() {
digitalWrite(this->pinA, LOW);
digitalWrite(this->pinB, HIGH);
if (this->pinPWM >= 0) {
// digitalWrite(this->pinPWM, HIGH);
analogWrite(this->pinPWM, 255);
}
}
void Motor::parar() {
digitalWrite(this->pinA, LOW);
digitalWrite(this->pinB, LOW);
if (this->pinPWM >= 0) {
digitalWrite(this->pinPWM, LOW);
}
}