void step( int number_of_steps );
void step( int number_of_steps );
Rotates stepper motor at the speed set in setSpeed.
|
Parameters |
Description |
|
int number_of_steps |
Steps of stepper motor. Positive value means rotating in one direction; negative value means rotating in the opposite direction. |
None.
#include <Stepper.h> #define STEPS 100 // Set up by particular stepper motor. // The 4-pin stepper motor, connecting 4 pins. Stepper stepper(STEPS, 8, 9, 10, 11); int prev = 0; // Reserve the previous value. void setup() { stepper.setSpeed(40); // Sets up rotation speed to 40 RPMs. } void loop() { int value = analogRead(0); // Gets data from the sensor. stepper.step(value- prev); // The movement. prev = value; // Records the previous displacement. }
Stepper.h