Advertisement
celem

accellstepper 28BYJ-48

Jan 17th, 2012
5,790
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.99 KB | None | 0 0
  1. // accellsteppertest.ino
  2. // Runs one stepper forwards and backwards, accelerating and decelerating
  3. // at the limits. Derived from example code by Mike McCauley
  4. // Set for 28BYJ-48 stepper
  5.  
  6. #include <AccelStepper.h>
  7.  
  8. #define FULLSTEP 4
  9. #define HALFSTEP 8
  10.  
  11. //declare variables for the motor pins
  12. int motorPin1 = 8;  // Blue   - 28BYJ48 pin 1
  13. int motorPin2 = 9;  // Pink   - 28BYJ48 pin 2
  14. int motorPin3 = 10; // Yellow - 28BYJ48 pin 3
  15. int motorPin4 = 11; // Orange - 28BYJ48 pin 4
  16.                         // Red    - 28BYJ48 pin 5 (VCC)
  17.  
  18. // The sequence 1-3-2-4 required for proper sequencing of 28BYJ48
  19. AccelStepper stepper2(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
  20.  
  21. void setup()
  22. {    
  23.   stepper2.setMaxSpeed(1000.0);
  24.   stepper2.setAcceleration(50.0);
  25.   stepper2.setSpeed(200);
  26.   stepper2.moveTo(2048);
  27. }
  28.  
  29. void loop()
  30. {
  31.   //Change direction at the limits
  32.   if (stepper2.distanceToGo() == 0) {
  33.     stepper2.moveTo(-stepper2.currentPosition());
  34.   }
  35.   stepper2.run();
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement