Accessories
Arduino for motors and lights library.
PortOnePin.cpp
1 /*************************************************************
2 project: <Accessories>
3 author: <Thierry PARIS>
4 description: <Driver port for a relay>
5 *************************************************************/
6 
7 #include "Accessories.h"
8 
9 #ifndef NO_MOTOR_LIGHT
10 
12 {
13  this->pin = -1;
14 }
15 
16 void PortOnePin::begin(int inPin, PIN_TYPE inType)
17 {
18  this->pinType = inType;
19  this->pin = this->beginPin(inPin);
20 }
21 
22 int PortOnePin::SetSpeed(int inSpeed)
23 {
24 #ifdef ACCESSORIES_DEBUG_MODE
25  if (inSpeed != 0 && inSpeed != 255 && this->pinType < ANALOG)
26  {
27  Serial.print(F(" PortOnePin "));
28  Serial.print(this->GetPin());
29  Serial.print(F(" SetSpeed() error : The port must be ANALOG or ANALOG_INVERTED !"));
30  }
31 #endif
32  return Port::SetSpeed(inSpeed);
33 }
34 
35 void PortOnePin::MoveLeftDir(unsigned long inDuration)
36 {
37 #ifdef ACCESSORIES_DEBUG_MODE
38  Serial.print(F(" PortOnePin "));
39  Serial.print(this->GetPin());
40  Serial.print(F(" MoveLeftDir() "));
41  if (inDuration != 0)
42  {
43  Serial.print(F("for "));
44  Serial.print(inDuration);
45  Serial.println(F("ms"));
46  }
47  else
48  Serial.println("");
49 #endif
50  this->state = PORT_LEFT;
51  this->MovePin(this->pin, HIGH);
52 }
53 
54 void PortOnePin::MoveRightDir(unsigned long inDuration)
55 {
56 #ifdef ACCESSORIES_DEBUG_MODE
57  Serial.print(F(" PortOnePin "));
58  Serial.print(this->GetPin());
59  Serial.print(F(" MoveRightDir() "));
60  if (inDuration != 0)
61  {
62  Serial.print(F("for "));
63  Serial.print(inDuration);
64  Serial.println(F("ms"));
65  }
66  else
67  Serial.println("");
68 #endif
69  this->state = PORT_RIGHT;
70  this->MovePin(this->pin, HIGH);
71 }
72 
74 {
75 #ifdef ACCESSORIES_DEBUG_MODE
76  Serial.print(F(" PortOnePin "));
77  Serial.print(this->GetPin());
78  Serial.println(F(" MoveStop()"));
79 #endif
80  this->state = PORT_STOP;
81  this->MovePin(this->pin, LOW);
82 }
83 
84 #ifdef ACCESSORIES_PRINT_ACCESSORIES
85 void PortOnePin::printPort()
86 {
87  Serial.print(F("[PortOnePin pin:"));
88  Port::printPortPin(this->pin, this->pinType);
89  Serial.print(F("]"));
90 }
91 #endif
92 
93 #endif
94 
void MoveStop()
Definition: PortOnePin.cpp:73
void MoveRightDir(unsigned long inDuration = 0)
Definition: PortOnePin.cpp:54
PORT_STATE state
Definition: Port.hpp:67
void MoveLeftDir(unsigned long inDuration = 0)
Definition: PortOnePin.cpp:35
virtual int SetSpeed(int inSpeed)
Definition: Port.cpp:108
void MovePin(int inPin, int inValue, PIN_TYPE inType = UNDEFINED) const
Definition: Port.cpp:92
int GetPin() const
Definition: PortOnePin.hpp:43
int SetSpeed(int inSpeed)
Definition: PortOnePin.cpp:22
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