Accessories
Arduino for motors and lights library.
PortStepper.cpp
1 /*************************************************************
2 project: <Accessories>
3 author: <Thierry PARIS>
4 description: <Port for a stepper motor>
5 *************************************************************/
6 
7 #include "Accessories.h"
8 
9 #ifndef NO_STEPPER
10 
12 {
13 }
14 
15 void PortStepper::begin(uint8_t inPin1, uint8_t inPin2, PIN_TYPE inType, uint8_t *inpSteps)
16 {
17  this->begin(inPin1, inPin2, 255, 255, inType, inpSteps);
18 }
19 
20 void PortStepper::begin(uint8_t inPin1, uint8_t inPin2, uint8_t inPin3, uint8_t inPin4, PIN_TYPE inType, uint8_t *inpSteps)
21 {
22  // Check ANALOG because stepper do not use GPIO_t ...
23  CHECKPIN(inPin1, ANALOG, "PortStepper::begin");
24  CHECKPIN(inPin2, ANALOG, "PortStepper::begin");
25  if (inPin3 == 255)
26  this->pMotor = new LocoStepper(inPin1, inPin2, inpSteps);
27  else
28  {
29  CHECKPIN(inPin3, ANALOG, "PortStepper::begin");
30  CHECKPIN(inPin4, ANALOG, "PortStepper::begin");
31  this->pMotor = new LocoStepper(inPin1, inPin2, inPin3, inPin4, inpSteps);
32  }
33 
34 #ifdef ACCESSORIES_PRINT_ACCESSORIES
35  this->printPin1 = inPin1;
36  this->printPin2 = inPin2;
37  this->printPin3 = inPin3;
38  this->printPin4 = inPin4;
39 
40  this->printType = inType;
41  this->printpSteps = inpSteps;
42 #endif
43 }
44 
45 void PortStepper::MovePosition(unsigned long inDuration, int inPosition)
46 {
47  this->pMotor->setSpeed((float)this->GetSpeed());
48  this->pMotor->moveTo(inPosition);
49 
50 #ifdef ACCESSORIES_DEBUG_MODE
51  Serial.print(F(" PortStepper MovePosition() "));
52  Serial.print(F("to "));
53  Serial.println(inPosition);
54 #endif
55 }
56 
57 void PortStepper::MoveRelativePosition(unsigned long inDuration, int inPosition)
58 {
59  this->pMotor->setSpeed((float)this->GetSpeed());
60  this->pMotor->move(inPosition);
61 
62 #ifdef ACCESSORIES_DEBUG_MODE
63  Serial.print(F(" PortStepper MoveRelativePosition() "));
64  Serial.print(F("for "));
65  Serial.print(inPosition);
66  Serial.println(F(" steps."));
67 #endif
68 }
69 
70 #ifdef ACCESSORIES_PRINT_ACCESSORIES
71 void PortStepper::printPort()
72 {
73  byte count = 2;
74 
75  Serial.print(F("[PortStepper pin1:"));
76  Port::printPortPin(this->printPin1, DIGITAL);
77  Serial.print(F(" pin2:"));
78  Port::printPortPin(this->printPin2, DIGITAL);
79  if (this->printPin3 != 255)
80  {
81  Serial.print(F(" pin3:"));
82  Port::printPortPin(this->printPin3, DIGITAL);
83  }
84  if (this->printPin4 != 255)
85  {
86  Serial.print(F(" pin4:"));
87  Port::printPortPin(this->printPin4, DIGITAL);
88  count = 4;
89  }
90  Serial.print(F(" steps:"));
91  for (int i = 0; i < count; i++)
92  {
93  if (i > 0)
94  Serial.print("/");
95  Serial.print(this->printpSteps[i], DEC);
96  }
97 
98  Serial.print(F("]"));
99 }
100 #endif
101 #endif
void move(long relative)
Definition: LocoStepper.cpp:63
void MoveRelativePosition(unsigned long inDuration, int inIncrementalPosition)
Definition: PortStepper.cpp:57
void moveTo(long absolute)
Definition: LocoStepper.cpp:49
int GetSpeed() const
Definition: Port.hpp:129
void setSpeed(float speed)
void MovePosition(unsigned long inDuration, int inEndPosition)
Definition: PortStepper.cpp:45
Support for stepper motors with acceleration etc.
Definition: LocoStepper.h:81
LocoStepper * pMotor
Definition: PortStepper.hpp:29
virtual void begin()
Definition: Port.hpp:117