lukacjusz

AccelStepper-Arduino-L298N

Aug 2nd, 2016
2,664
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.67 KB | None | 0 0
  1. #include <AccelStepper.h>
  2. #define HALFSTEP 8
  3.  
  4. // Motor pin definitions
  5. #define motorPin1  10
  6. #define motorPin2  11
  7. #define motorPin3  12
  8. #define motorPin4  13
  9.  
  10. // Initialize with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper
  11. AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4);
  12.  
  13. void setup() {
  14.   stepper1.setMaxSpeed(5000.0);
  15.   stepper1.setAcceleration(100.0);
  16.   stepper1.setSpeed(600);
  17.   stepper1.moveTo(10000);
  18.  
  19. }//--(end setup )---
  20.  
  21. void loop() {
  22.  
  23.   //Change direction when the stepper reaches the target position
  24.   if (stepper1.distanceToGo() == 0) {
  25.     stepper1.moveTo(-stepper1.currentPosition());
  26.   }
  27.   stepper1.run();
  28. }
Advertisement
Add Comment
Please, Sign In to add comment