forked from adafruit/AccelStepper
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Examples showing function-wrapping for step procedure
- Loading branch information
Showing
2 changed files
with
93 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// ConstantSpeed.pde | ||
// -*- mode: C++ -*- | ||
// | ||
// Shows how to run AccelStepper in the simplest, | ||
// fixed speed mode with no accelerations | ||
// Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library) | ||
// And AccelStepper with AFMotor support (https://github.com/adafruit/AccelStepper) | ||
// Public domain! | ||
|
||
#include <AccelStepper.h> | ||
#include <AFMotor.h> | ||
|
||
AF_Stepper motor1(200, 1); | ||
|
||
|
||
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP! | ||
void forwardstep() { | ||
motor1.onestep(FORWARD, SINGLE); | ||
} | ||
void backwardstep() { | ||
motor1.onestep(BACKWARD, SINGLE); | ||
} | ||
|
||
AccelStepper stepper(forwardstep, backwardstep); // use functions to step | ||
|
||
void setup() | ||
{ | ||
Serial.begin(9600); // set up Serial library at 9600 bps | ||
Serial.println("Stepper test!"); | ||
|
||
stepper.setSpeed(50); | ||
} | ||
|
||
void loop() | ||
{ | ||
stepper.runSpeed(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
// MultiStepper | ||
// -*- mode: C++ -*- | ||
// | ||
// Control both Stepper motors at the same time with different speeds | ||
// and accelerations. | ||
// Requires the AFMotor library (https://github.com/adafruit/Adafruit-Motor-Shield-library) | ||
// And AccelStepper with AFMotor support (https://github.com/adafruit/AccelStepper) | ||
// Public domain! | ||
|
||
#include <AccelStepper.h> | ||
#include <AFMotor.h> | ||
|
||
// two stepper motors one on each port | ||
AF_Stepper motor1(200, 1); | ||
AF_Stepper motor2(200, 2); | ||
|
||
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP! | ||
// wrappers for the first motor! | ||
void forwardstep1() { | ||
motor1.onestep(FORWARD, SINGLE); | ||
} | ||
void backwardstep1() { | ||
motor1.onestep(BACKWARD, SINGLE); | ||
} | ||
// wrappers for the second motor! | ||
void forwardstep2() { | ||
motor2.onestep(FORWARD, SINGLE); | ||
} | ||
void backwardstep2() { | ||
motor2.onestep(BACKWARD, SINGLE); | ||
} | ||
|
||
// Motor shield has two motor ports, now we'll wrap them in an AccelStepper object | ||
AccelStepper stepper1(forwardstep1, backwardstep1); | ||
AccelStepper stepper2(forwardstep2, backwardstep2); | ||
|
||
void setup() | ||
{ | ||
stepper1.setMaxSpeed(200.0); | ||
stepper1.setAcceleration(100.0); | ||
stepper1.moveTo(24); | ||
|
||
stepper2.setMaxSpeed(300.0); | ||
stepper2.setAcceleration(100.0); | ||
stepper2.moveTo(1000000); | ||
|
||
} | ||
|
||
void loop() | ||
{ | ||
// Change direction at the limits | ||
if (stepper1.distanceToGo() == 0) | ||
stepper1.moveTo(-stepper1.currentPosition()); | ||
stepper1.run(); | ||
stepper2.run(); | ||
} |