There are no unnecessary lines in that sketch, if you want to use Accelstepper with Adafruits Motorshield v2.
Structurally, there is a declaration portion:
#include <AccelStepper.h>
#include <Wire.h>
#include <Adafruit_MotorShield.h>
#include "utility/Adafruit_PWMServoDriver.h"
Adafruit_MotorShield AFMSbot(0x61); // Rightmost jumper closed
// Connect two steppers with 200 steps per revolution (1.8 degree) to the top shield
Adafruit_StepperMotor *myStepper1 = AFMSbot.getStepper(200, 1);
Adafruit_StepperMotor *myStepper2 = AFMSbot.getStepper(200, 2);
// wrappers for the first motor!
void forwardstep1() {myStepper1->onestep(FORWARD, SINGLE);}
void backwardstep1() {myStepper1->onestep(BACKWARD, SINGLE);}
// wrappers for the second motor!
void forwardstep2() {myStepper2->onestep(FORWARD, DOUBLE);}
void backwardstep2() {myStepper2->onestep(BACKWARD, DOUBLE);}
// Now we'll wrap the 2 steppers in an AccelStepper object
AccelStepper stepper1(forwardstep1, backwardstep1);
AccelStepper stepper2(forwardstep2, backwardstep2);
That will need to be at the top of any code you use this in. Each line in this builds on the previous declaration. Working backwards from the end,
- AccelStepper stepper1 is built with two functions forwardstep1, backwardstep1. It wraps and uses these two functions.
- forwardstep1 and backwardstep1 are both based on a function (.onestep(...)) from myStepper1. They wrap access to myStepper1.
- myStepper1 is created from AFMSbot.
- The lines with #include at the beginning load up pre-written blocks of code that you'll use to control. One of these, obviously is Accelstepper.
In practice, you will only actually use the very last object - stepper1 (and stepper2).
There is a procedural set up portion
You can probably read this easily enough, the only cryptic line is the first one AFMSbot.begin(). Don't worry about it, but it does need to be in your code somewhere before you try to use the motorshield.
The looping bit is easy:
void loop()
{
stepper1.run();
stepper2.run();
}
Consider whether you need accelstepper - it's got great features, but if you don't need them then it is an extra layer of indirection that maybe you don't need.
Adafruit_MotorShield/StepperTest.ino is an example of the standard way of doing things.
sn