-
-
Notifications
You must be signed in to change notification settings - Fork 7
/
MotorControl.cpp
52 lines (44 loc) · 889 Bytes
/
MotorControl.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
#include "MotorControl.h"
MotorControl::MotorControl(int pinA, int pinB)
{
_pinA = pinA;
_pinB = pinB;
_motorDirection = 0;
}
void MotorControl::clockwise()
{
digitalWrite(_pinA, HIGH);
digitalWrite(_pinB, LOW);
Serial.println("[STATUS] - Motor turning clockwise");
}
void MotorControl::countClockwise()
{
digitalWrite(_pinA, LOW);
digitalWrite(_pinB, HIGH);
Serial.println("[STATUS] - Motor turning counter clockwise");
}
void MotorControl::stop()
{
digitalWrite(_pinA, LOW);
digitalWrite(_pinB, LOW);
}
void MotorControl::determineMotorDirectionAndBegin()
{
stop();
if (_motorDirection)
{
clockwise();
}
else
{
countClockwise();
}
}
int MotorControl::getMotorDirection()
{
return _motorDirection;
}
void MotorControl::setMotorDirection(int direction)
{
_motorDirection = direction;
}