Created
July 10, 2020 22:05
-
-
Save chris-schmitz/52903f54ba1e73eee116741b76adcdf1 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// ConstantSpeed.pde | |
// -*- mode: C++ -*- | |
// | |
// Shows how to run AccelStepper in the simplest, | |
// fixed speed mode with no accelerations | |
// Requires the Adafruit_Motorshield v2 library | |
// https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library | |
// And AccelStepper with AFMotor support | |
// https://github.com/adafruit/AccelStepper | |
// This tutorial is for Adafruit Motorshield v2 only! | |
// Will not work with v1 shields | |
#include <AccelStepper.h> | |
#include <Adafruit_MotorShield.h> | |
#include <Wire.h> | |
// Create the motor shield object with the default I2C address | |
Adafruit_MotorShield AFMS = Adafruit_MotorShield(); | |
// Or, create it with a different I2C address (say for stacking) | |
// Adafruit_MotorShield AFMS = Adafruit_MotorShield(0x61); | |
// Connect a stepper motor with 200 steps per revolution (1.8 degree) | |
// to motor port #2 (M3 and M4) | |
Adafruit_StepperMotor *myStepper1 = AFMS.getStepper(200, 2); | |
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP! | |
void forwardstep1() | |
{ | |
myStepper1->onestep(FORWARD, SINGLE); | |
} | |
void backwardstep1() | |
{ | |
myStepper1->onestep(BACKWARD, SINGLE); | |
} | |
AccelStepper Astepper1(forwardstep1, backwardstep1); // use functions to step | |
void setup() | |
{ | |
Serial.begin(9600); // set up Serial library at 9600 bps | |
Serial.println("Stepper test!"); | |
AFMS.begin(); // create with the default frequency 1.6KHz | |
//AFMS.begin(1000); // OR with a different frequency, say 1KHz | |
Astepper1.moveTo(5000); | |
Astepper1.setSpeed(200); | |
} | |
void loop() | |
{ | |
Astepper1.runSpeed(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment