-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMotor.cpp
More file actions
31 lines (20 loc) · 766 Bytes
/
Motor.cpp
File metadata and controls
31 lines (20 loc) · 766 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
#include "Motor.h"
Motor::Motor(int pwmPin, int direcaoPin):PWM_PIN(pwmPin), DIRECAO_PIN(direcaoPin){
}
void Motor::config(){
pinMode(PWM_PIN,OUTPUT);
pinMode(DIRECAO_PIN,OUTPUT);
}
void Motor::acionar(float percentualTensao){
if(percentualTensao < -100)
percentualTensao = -100; //se o valor passado em valor_por_cento for menor que -100 obriga-se o mmotor a ficar em -100
if(percentualTensao > 100)
percentualTensao = 100; //se o valor passado em valor_por_cento for maior que 100 obriga-se o mmotor a ficar em 100
if(percentualTensao < 0){
digitalWrite(DIRECAO_PIN, false);
}else{
digitalWrite(DIRECAO_PIN, true);
percentualTensao = 100 - percentualTensao;
}
analogWrite(PWM_PIN, 255*(abs(percentualTensao))/100.0);
}