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