-
-
Notifications
You must be signed in to change notification settings - Fork 33
/
adafruit_motor_driver.h
45 lines (40 loc) · 962 Bytes
/
adafruit_motor_driver.h
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
/**
* @file adafruit_motor_driver.h
* @brief Motor device driver for the Adafruit motor shield.
* @author Miguel Grinberg
*/
#include "motor_driver.h"
namespace Michelino
{
class Motor : public MotorDriver
{
public:
/*
* @brief Class constructor.
* @param number the DC motor number to control, from 1 to 4.
*/
Motor(int number)
: MotorDriver(), motor(number), currentSpeed(0)
{
}
void setSpeed(int speed)
{
currentSpeed = speed;
if (speed >= 0) {
motor.setSpeed(speed);
motor.run(FORWARD);
}
else {
motor.setSpeed(-speed);
motor.run(BACKWARD);
}
}
int getSpeed() const
{
return currentSpeed;
}
private:
AF_DCMotor motor;
int currentSpeed;
};
};