Accessories
Arduino for motors and lights library.
PortTwoPinsEnable.cpp
1 /*************************************************************
2 project: <Accessories>
3 author: <Thierry PARIS>
4 description: <Driver port with 2 pins and an Enable pin>
5 *************************************************************/
6 
7 #include "Accessories.h"
8 
10 {
11 }
12 
13 void PortTwoPinsEnable::begin(int inPinA, int inPinB, PIN_TYPE inType, int inPinEnable, PIN_TYPE inTypeEnable)
14 {
15  this->PortTwoPins::begin(inPinA, inPinB, inType);
16 
17  this->pinTypeEnable = inTypeEnable;
18  this->pinEnable = this->beginPin(inPinEnable, inTypeEnable);
19 
20  CHECKPIN(this->pinEnable, inType, "PortTwoPinsEnable::begin");
21 }
22 
23 void PortTwoPinsEnable::MoveLeftDir(unsigned long inDuration)
24 {
25 #ifdef ACCESSORIES_DEBUG_MODE
26  Serial.print(this->GetPinA());
27  Serial.print(F(" / "));
28  Serial.print(this->GetPinB());
29  Serial.print(F(" PortTwoPinsEnable MoveLeftDir() "));
30  if (inDuration != 0)
31  {
32  Serial.print(F("for "));
33  Serial.print(inDuration);
34  Serial.println(F("ms"));
35  }
36  else
37  Serial.println("");
38 #endif
39 
40  this->Move(LOW, HIGH, HIGH);
41 
42  if (inDuration != 0)
43  {
44  delay(inDuration);
45 
46  this->Move(LOW, LOW, LOW);
47  }
48 
49  this->state = PORT_LEFT;
50 }
51 
52 void PortTwoPinsEnable::MoveRightDir(unsigned long inDuration)
53 {
54 #ifdef ACCESSORIES_DEBUG_MODE
55  Serial.print(this->GetPinA());
56  Serial.print(F(" / "));
57  Serial.print(this->GetPinB());
58  Serial.print(F(" PortTwoPinsEnable MoveRightDir() "));
59  if (inDuration != 0)
60  {
61  Serial.print(F("for "));
62  Serial.print(inDuration);
63  Serial.println(F("ms"));
64  }
65  else
66  Serial.println("");
67 #endif
68 
69  this->Move(HIGH, LOW, HIGH);
70 
71  if (inDuration != 0)
72  {
73  delay(inDuration);
74 
75  this->Move(LOW, LOW, LOW);
76  }
77 
78  this->state = PORT_RIGHT;
79 }
80 
82 {
83 #ifdef ACCESSORIES_DEBUG_MODE
84  Serial.print(this->GetPinA());
85  Serial.print(F(" / "));
86  Serial.print(this->GetPinB());
87  Serial.println(F(" PortTwoPinsEnable MoveStop() "));
88 #endif
89 
90  this->Move(LOW, LOW, LOW);
91 
92  this->state = PORT_STOP;
93 }
94 
95 void PortTwoPinsEnable::Move(int inValA, int inValB, int inValEnable)
96 {
97  MovePin(this->pinA, inValA);
98  MovePin(this->pinB, inValB);
99 
100  MovePin(this->pinEnable, inValEnable, this->pinTypeEnable);
101 }
102 
103 #ifdef ACCESSORIES_PRINT_ACCESSORIES
104 void PortTwoPinsEnable::printPort()
105 {
106  Serial.print(F("[PortTwoPinsEnable pinA:"));
107  Port::printPortPin(this->pinA, this->pinType);
108  Serial.print(F(" pinB:"));
109  Port::printPortPin(this->pinB, this->pinType);
110  Serial.print(F(" enable:"));
111  Port::printPortPin(this->pinEnable, this->pinTypeEnable);
112  Serial.print(F("]"));
113 }
114 #endif
PIN_TYPE pinType
Definition: Port.hpp:65
void MovePin(int inPin, int inValue, PIN_TYPE inType = UNDEFINED) const
Definition: Port.cpp:92
void MoveRightDir(unsigned long inDuration = 0)
PORT_STATE state
Definition: Port.hpp:67
int GetPinB() const
Definition: PortTwoPins.hpp:50
int GetPinA() const
Definition: PortTwoPins.hpp:42
void MoveLeftDir(unsigned long inDuration = 0)
int beginPin(int inPin, PIN_TYPE inType = UNDEFINED) const
Definition: Port.cpp:74
virtual void begin()
Definition: Port.hpp:99