-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNodeMotorDriver.cpp
More file actions
58 lines (51 loc) · 1.27 KB
/
NodeMotorDriver.cpp
File metadata and controls
58 lines (51 loc) · 1.27 KB
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
53
54
55
56
57
58
/*
NodeMotorDriver.h - Library for use with NodeMCU L293D driver board
MIT License
*/
#include "NodeMotorDriver.h"
NodeMotorDriver::NodeMotorDriver(uint8_t pinMotorA1, uint8_t pinMotorA2, uint8_t pinMotorB1, uint8_t pinMotorB2)
{
pinMode(pinMotorA1, OUTPUT);
pinMode(pinMotorA2, OUTPUT);
pinMode(pinMotorB1, OUTPUT);
pinMode(pinMotorB2, OUTPUT);
m_pinA1 = pinMotorA1; // speed
m_pinA2 = pinMotorA2; // direction
m_pinB1 = pinMotorB1; // speed
m_pinB2 = pinMotorB2; // direction
}
void NodeMotorDriver::goForward(uint16_t pwm)
{
analogWrite(m_pinA1, pwm);
digitalWrite(m_pinA2, HIGH);
analogWrite(m_pinB1, pwm);
digitalWrite(m_pinB2, HIGH);
}
void NodeMotorDriver::goBackward(uint16_t pwm)
{
analogWrite(m_pinA1, pwm);
digitalWrite(m_pinA2, LOW);
analogWrite(m_pinB1, pwm);
digitalWrite(m_pinB2, LOW);
}
void NodeMotorDriver::turnRight(uint16_t pwm)
{
analogWrite(m_pinA1, pwm);
digitalWrite(m_pinA2, HIGH);
analogWrite(m_pinB1, pwm);
digitalWrite(m_pinB2, LOW);
}
void NodeMotorDriver::turnLeft(uint16_t pwm)
{
analogWrite(m_pinA1, pwm);
digitalWrite(m_pinA2, LOW);
analogWrite(m_pinB1, pwm);
digitalWrite(m_pinB2, HIGH);
}
void NodeMotorDriver::stop()
{
analogWrite(m_pinA1, 0);
digitalWrite(m_pinA2, 0);
analogWrite(m_pinB1, 0);
digitalWrite(m_pinB2, 0);
}