Accessories
Arduino for motors and lights library.
PortShieldL293d.cpp
1 /*************************************************************
2 project: <Accessories>
3 author: <Thierry PARIS>
4 description: <Driver port for L293n>
5 *************************************************************/
6 
7 #if !defined(__AVR_ATmega32U4__)
8 
9 #include "Accessories.h"
10 
11 #ifndef NO_SHIELDL293D
12 
14 {
15 }
16 
17 void PortShieldL293d::begin(unsigned char inOutPort, uint8_t inSpeed, uint8_t inFreq)
18 {
19  this->pmotor = new AF_DCMotor(inOutPort, inFreq);
20  this->pmotor->pwmfreq = inFreq;
21  this->pmotor->setSpeed(inSpeed);
22 
23 #ifdef ACCESSORIES_PRINT_ACCESSORIES
24  this->printedOutPort = inOutPort;
25  this->printedSpeed = inSpeed;
26 #endif
27 
28  this->pmotor->run(RELEASE);
29 }
30 
31 int PortShieldL293d::SetSpeed(uint8_t inSpeed)
32 {
33  int oldspeed = Port::SetSpeed(inSpeed);
34  this->pmotor->setSpeed(inSpeed);
35  return oldspeed;
36 }
37 
38 void PortShieldL293d::MoveLeftDir(unsigned long inDuration)
39 {
40 #ifdef ACCESSORIES_DEBUG_MODE
41  Serial.print(F(" PortShieldL293d MoveLeftDir() "));
42  if (inDuration != 0)
43  {
44  Serial.print(F("for "));
45  Serial.print(inDuration);
46  Serial.println(F("ms"));
47  }
48  else
49  Serial.println("");
50 #endif
51  this->pmotor->run(FORWARD);
52  if (inDuration != 0)
53  {
54  delay(inDuration);
55  this->pmotor->run(RELEASE);
56  }
57 
58  this->SetPortState(PORT_LEFT);
59 }
60 
61 void PortShieldL293d::MoveRightDir(unsigned long inDuration)
62 {
63 #ifdef ACCESSORIES_DEBUG_MODE
64  Serial.print(F(" PortShieldL293d MoveRightDir() "));
65  if (inDuration != 0)
66  {
67  Serial.print(F("for "));
68  Serial.print(inDuration);
69  Serial.println(F("ms"));
70  }
71  else
72  Serial.println("");
73 #endif
74  this->pmotor->run(BACKWARD);
75  if (inDuration != 0)
76  {
77  delay(inDuration);
78  this->pmotor->run(RELEASE);
79  }
80 
81  this->SetPortState(PORT_RIGHT);
82 }
83 
85 {
86  this->pmotor->run(RELEASE);
87  this->SetPortState(PORT_STOP);
88 }
89 
90 #ifdef ACCESSORIES_PRINT_ACCESSORIES
91 void PortShieldL293d::printPort()
92 {
93  Serial.print(F("[PortShieldL293d port: M"));
94  Serial.print((int)this->printedOutPort, DEC);
95  Serial.print(F(" speed:"));
96  Serial.print((int)this->printedSpeed, DEC);
97  Serial.print(F("]"));
98 }
99 #endif
100 #endif
101 #endif
void MoveRightDir(unsigned long inDuration = 0)
void MoveLeftDir(unsigned long inDuration = 0)
virtual int SetSpeed(int inSpeed)
Definition: Port.cpp:178
int SetSpeed(uint8_t inSpeed)
AF_DCMotor * pmotor
void SetPortState(PORT_STATE inState)
Definition: Port.hpp:87
virtual void begin()
Definition: Port.hpp:117