AFMotor_ConstantSpeed.pde 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. // AFMotor_ConstantSpeed.pde
  2. // -*- mode: C++ -*-
  3. //
  4. // Shows how to run AccelStepper in the simplest,
  5. // fixed speed mode with no accelerations
  6. // Requires the AFMotor library
  7. // (https://github.com/adafruit/Adafruit-Motor-Shield-library)
  8. // Caution, does not work with Adafruit Motor Shield V2
  9. // See https://github.com/adafruit/Adafruit_Motor_Shield_V2_Library
  10. // for examples that work with Adafruit Motor Shield V2.
  11. #include <AccelStepper.h>
  12. #include <AFMotor.h>
  13. AF_Stepper motor1(200, 1);
  14. // you can change these to DOUBLE or INTERLEAVE or MICROSTEP!
  15. void forwardstep() {
  16. motor1.onestep(FORWARD, SINGLE);
  17. }
  18. void backwardstep() {
  19. motor1.onestep(BACKWARD, SINGLE);
  20. }
  21. AccelStepper stepper(forwardstep, backwardstep); // use functions to step
  22. void setup()
  23. {
  24. Serial.begin(9600); // set up Serial library at 9600 bps
  25. Serial.println("Stepper test!");
  26. stepper.setMaxSpeed(50);
  27. stepper.setSpeed(50);
  28. }
  29. void loop()
  30. {
  31. stepper.runSpeed();
  32. }