Arduino  1.8.10
Stepper クラス

#include <Stepper.h>

公開メンバ関数

 Stepper (int number_of_steps, int motor_pin_1, int motor_pin_2)
 
 Stepper (int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4)
 
 Stepper (int number_of_steps, int motor_pin_1, int motor_pin_2, int motor_pin_3, int motor_pin_4, int motor_pin_5)
 
void setSpeed (long whatSpeed)
 
void step (int number_of_steps)
 
int version (void)
 

詳解

Stepper.h83 行目に定義があります。

構築子と解体子

◆ Stepper() [1/3]

Stepper::Stepper ( int  number_of_steps,
int  motor_pin_1,
int  motor_pin_2 
)

Stepper.cpp85 行目に定義があります。

86 {
87  this->step_number = 0; // which step the motor is on
88  this->direction = 0; // motor direction
89  this->last_step_time = 0; // time stamp in us of the last step taken
90  this->number_of_steps = number_of_steps; // total number of steps for this motor
91 
92  // Arduino pins for the motor control connection:
93  this->motor_pin_1 = motor_pin_1;
94  this->motor_pin_2 = motor_pin_2;
95 
96  // setup the pins on the microcontroller:
97  pinMode(this->motor_pin_1, OUTPUT);
98  pinMode(this->motor_pin_2, OUTPUT);
99 
100  // When there are only 2 pins, set the others to 0:
101  this->motor_pin_3 = 0;
102  this->motor_pin_4 = 0;
103  this->motor_pin_5 = 0;
104 
105  // pin_count is used by the stepMotor() method:
106  this->pin_count = 2;
107 }
void pinMode(uint8_t, uint8_t)
#define OUTPUT
Definition: Arduino.h:44

◆ Stepper() [2/3]

Stepper::Stepper ( int  number_of_steps,
int  motor_pin_1,
int  motor_pin_2,
int  motor_pin_3,
int  motor_pin_4 
)

Stepper.cpp114 行目に定義があります。

116 {
117  this->step_number = 0; // which step the motor is on
118  this->direction = 0; // motor direction
119  this->last_step_time = 0; // time stamp in us of the last step taken
120  this->number_of_steps = number_of_steps; // total number of steps for this motor
121 
122  // Arduino pins for the motor control connection:
123  this->motor_pin_1 = motor_pin_1;
124  this->motor_pin_2 = motor_pin_2;
125  this->motor_pin_3 = motor_pin_3;
126  this->motor_pin_4 = motor_pin_4;
127 
128  // setup the pins on the microcontroller:
129  pinMode(this->motor_pin_1, OUTPUT);
130  pinMode(this->motor_pin_2, OUTPUT);
131  pinMode(this->motor_pin_3, OUTPUT);
132  pinMode(this->motor_pin_4, OUTPUT);
133 
134  // When there are 4 pins, set the others to 0:
135  this->motor_pin_5 = 0;
136 
137  // pin_count is used by the stepMotor() method:
138  this->pin_count = 4;
139 }
void pinMode(uint8_t, uint8_t)
#define OUTPUT
Definition: Arduino.h:44

◆ Stepper() [3/3]

Stepper::Stepper ( int  number_of_steps,
int  motor_pin_1,
int  motor_pin_2,
int  motor_pin_3,
int  motor_pin_4,
int  motor_pin_5 
)

Stepper.cpp145 行目に定義があります。

148 {
149  this->step_number = 0; // which step the motor is on
150  this->direction = 0; // motor direction
151  this->last_step_time = 0; // time stamp in us of the last step taken
152  this->number_of_steps = number_of_steps; // total number of steps for this motor
153 
154  // Arduino pins for the motor control connection:
155  this->motor_pin_1 = motor_pin_1;
156  this->motor_pin_2 = motor_pin_2;
157  this->motor_pin_3 = motor_pin_3;
158  this->motor_pin_4 = motor_pin_4;
159  this->motor_pin_5 = motor_pin_5;
160 
161  // setup the pins on the microcontroller:
162  pinMode(this->motor_pin_1, OUTPUT);
163  pinMode(this->motor_pin_2, OUTPUT);
164  pinMode(this->motor_pin_3, OUTPUT);
165  pinMode(this->motor_pin_4, OUTPUT);
166  pinMode(this->motor_pin_5, OUTPUT);
167 
168  // pin_count is used by the stepMotor() method:
169  this->pin_count = 5;
170 }
void pinMode(uint8_t, uint8_t)
#define OUTPUT
Definition: Arduino.h:44

関数詳解

◆ setSpeed()

void Stepper::setSpeed ( long  whatSpeed)

Stepper.cpp175 行目に定義があります。

176 {
177  this->step_delay = 60L * 1000L * 1000L / this->number_of_steps / whatSpeed;
178 }

◆ step()

void Stepper::step ( int  number_of_steps)

Stepper.cpp184 行目に定義があります。

185 {
186  int steps_left = abs(steps_to_move); // how many steps to take
187 
188  // determine direction based on whether steps_to_mode is + or -:
189  if (steps_to_move > 0) { this->direction = 1; }
190  if (steps_to_move < 0) { this->direction = 0; }
191 
192 
193  // decrement the number of steps, moving one step each time:
194  while (steps_left > 0)
195  {
196  unsigned long now = micros();
197  // move only if the appropriate delay has passed:
198  if (now - this->last_step_time >= this->step_delay)
199  {
200  // get the timeStamp of when you stepped:
201  this->last_step_time = now;
202  // increment or decrement the step number,
203  // depending on direction:
204  if (this->direction == 1)
205  {
206  this->step_number++;
207  if (this->step_number == this->number_of_steps) {
208  this->step_number = 0;
209  }
210  }
211  else
212  {
213  if (this->step_number == 0) {
214  this->step_number = this->number_of_steps;
215  }
216  this->step_number--;
217  }
218  // decrement the steps left:
219  steps_left--;
220  // step the motor to step number 0, 1, ..., {3 or 10}
221  if (this->pin_count == 5)
222  stepMotor(this->step_number % 10);
223  else
224  stepMotor(this->step_number % 4);
225  }
226  }
227 }
int abs(int __i) __ATTR_CONST__
unsigned long micros(void)
Definition: wiring.c:79

◆ version()

int Stepper::version ( void  )

Stepper.cpp362 行目に定義があります。

363 {
364  return 5;
365 }

このクラス詳解は次のファイルから抽出されました: