Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. /*-----( Import needed libraries )-----*/
  2. #include <Stepper.h>
  3.  
  4. /*-----( Declare Constants, Pin Numbers )-----*/
  5. //---( Number of steps per revolution of INTERNAL motor in 4-step mode )---
  6. #define STEPS_PER_MOTOR_REVOLUTION 32
  7.  
  8. //---( Steps per OUTPUT SHAFT of gear reduction )---
  9. #define STEPS_PER_OUTPUT_REVOLUTION 32 * 64 //2048
  10.  
  11. //The pin connections need to be 4 pins connected
  12. // to Motor Driver In1, In2, In3, In4 and then the pins entered
  13. // here in the sequence 1-3-2-4 for proper sequencing
  14. Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 8, 10, 9, 11);
  15.  
  16. /*-----( Declare Variables )-----*/
  17. int Steps2Take;
  18.  
  19. void setup() /*----( SETUP: RUNS ONCE )----*/
  20. {
  21. // Nothing (Stepper Library sets pins as outputs)
  22. }
  23.  
  24. void loop() /*----( LOOP: RUNS CONSTANTLY )----*/
  25. {
  26. Steps2Take = STEPS_PER_OUTPUT_REVOLUTION / 4 ; // Rotate CW 1 turn
  27. small_stepper.setSpeed(700);
  28. small_stepper.step(Steps2Take);
  29. delay(0);
  30.  
  31. Steps2Take = - STEPS_PER_OUTPUT_REVOLUTION / 4; // Rotate CCW 1 turn
  32. small_stepper.setSpeed(700); // 700 a good max speed??
  33. small_stepper.step(Steps2Take);
  34. delay(0);
  35.  
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement