-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHBridge.cpp
38 lines (34 loc) · 873 Bytes
/
HBridge.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
#include "HBridge.h"
HBridge::HBridge(
bool orientation,
int port_IN1,
int port_IN2,
int port_STBY) :
_IN1(GPIOOutput(port_IN1)),
_IN2(GPIOOutput(port_IN2)),
_STBY(GPIOOutput(port_STBY)),
_orientation(orientation)
{
_STBY.set_value(HIGH);
set_direction(BRAKE);
}
void HBridge::set_direction(int direction)
{
_direction = direction;
switch(direction) {
case FORWARD:
_IN1.set_value(_orientation);
_IN2.set_value(!_orientation);
break;
case REVERSE:
_IN1.set_value(!_orientation);
_IN2.set_value(_orientation);
break;
case BRAKE:
_IN1.set_value(LOW);
_IN2.set_value(LOW);
break;
}
}
HBridge::~HBridge() {
}