-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathESC.cpp
executable file
·46 lines (41 loc) · 916 Bytes
/
ESC.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
/*
* A simple class for control an ESC controller
*/
#include <Servo.h>
#include "ESC.h"
ESC::ESC(int mode){
actualDirection = FORWARD;
setRunningMode(mode);
}
void ESC::setSpeed(unsigned int speed)
{
Serial.println(baseSpeed + speed);
if(actualDirection == FORWARD){
if(baseSpeed + speed <= MAX_PULSE)
esc.writeMicroseconds(baseSpeed + speed);
}else{
if(baseSpeed + speed >= MIN_PULSE)
esc.writeMicroseconds(baseSpeed - speed);
}
}
void ESC::setRunningMode(int mode){
if(mode == MODE_FORWARD_ONLY){
baseSpeed = BASE_FORWARD_ONLY;
}else if(mode == MODE_FORWARD_BACKWARD){
baseSpeed = BASE_FORWARD_BACKWARD;
}
}
void ESC::setDirection(int direction)
{
if(direction == FORWARD)
actualDirection = FORWARD;
else
actualDirection = BACKWARD;
}
void ESC::detach(){
esc.detach();
}
void ESC::attach(int pin){
esc.attach(pin);
//setSpeed(0);
}