Accessories
Arduino for motors and lights library.
PortOnePin.cpp
1 /*************************************************************
2 project: <Accessories>
3 author: <Thierry PARIS>
4 description: <Driver port with only one pin>
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->SetPinType(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->GetPinType() < ANALOG)
26  {
27  Serial.print(F(" PortOnePin "));
28  Port::printPortPin(this->pin, this->GetPinType());
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  Port::printPortPin(this->pin, this->GetPinType());
40  Serial.print(F(" MoveLeftDir() "));
41  if (inDuration != 0)
42  {
43  Serial.print(F("for "));
44  Serial.print(inDuration);
45  Serial.print(F("ms"));
46  }
47  Serial.print(F(" at speed "));
48  Serial.println(this->speed);
49 #endif
50  this->SetPortState(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  Port::printPortPin(this->pin, this->GetPinType());
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->SetPortState(PORT_RIGHT);
70  this->MovePin(this->pin, HIGH);
71 }
72 
74 {
75 #ifdef ACCESSORIES_DEBUG_MODE
76  Serial.print(F(" PortOnePin "));
77  Port::printPortPin(this->pin, this->GetPinType());
78  Serial.println(F(" MoveStop()"));
79 #endif
80  this->SetPortState(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->GetPinType());
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
void MovePin(int inPin, int inValue, PIN_TYPE inType = UNDEFINED) const
Definition: Port.cpp:138
int speed
Definition: Port.hpp:64
void MoveLeftDir(unsigned long inDuration = 0)
Definition: PortOnePin.cpp:35
virtual int SetSpeed(int inSpeed)
Definition: Port.cpp:181
PIN_TYPE GetPinType() const
Definition: Port.hpp:77
int SetSpeed(int inSpeed)
Definition: PortOnePin.cpp:22
int beginPin(int inPin, PIN_TYPE inType = UNDEFINED) const
Definition: Port.cpp:103
void SetPinType(PIN_TYPE inType)
Definition: Port.hpp:84
void SetPortState(PORT_STATE inState)
Definition: Port.hpp:87
virtual void begin()
Definition: Port.hpp:117