Advertisement
Guest User

Untitled

a guest
Dec 7th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.80 KB | None | 0 0
  1. /*
  2.  * Simple demo, should work with any driver board
  3.  *
  4.  * Connect STEP, DIR as indicated
  5.  *
  6.  * Copyright (C)2015 Laurentiu Badea
  7.  *
  8.  * This file may be redistributed under the terms of the MIT license.
  9.  * A copy of this license has been included with this distribution in the file LICENSE.
  10.  */
  11. #include <Arduino.h>
  12. #include "BasicStepperDriver.h"
  13.  
  14. // Motor steps per revolution. Most steppers are 200 steps or 1.8 degrees/step
  15. #define MOTOR_STEPS 200
  16.  
  17. // All the wires needed for full functionality
  18. #define DIR 8
  19. #define STEP 9
  20. //Uncomment line to use enable/disable functionality
  21. //#define ENBL 7
  22.  
  23. // Since microstepping is set externally, make sure this matches the selected mode
  24. // 1=full step, 2=half step etc.
  25. #define MICROSTEPS 1
  26.  
  27. // 2-wire basic config, microstepping is hardwired on the driver
  28. BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP);
  29.  
  30. //Uncomment line to use enable/disable functionality
  31. //BasicStepperDriver stepper(MOTOR_STEPS, DIR, STEP, ENBL);
  32.  
  33. void setup() {
  34.     /*
  35.      * Set target motor RPM.
  36.      * These motors can do up to about 200rpm.
  37.      * Too high will result in a high pitched whine and the motor does not move.
  38.      */
  39.     stepper.setRPM(120);
  40. }
  41.  
  42. void loop() {
  43.  
  44.     // energize coils - the motor will hold position
  45.     // stepper.enable();
  46.  
  47.     /*
  48.      * Tell the driver the microstep level we selected.
  49.      * If mismatched, the motor will move at a different RPM than chosen.
  50.      */
  51.     stepper.setMicrostep(MICROSTEPS);
  52.  
  53.     /*
  54.      * Moving motor one full revolution using the degree notation
  55.      */
  56.     stepper.rotate(360);
  57.  
  58.     /*
  59.      * Moving motor to original position using steps
  60.      */
  61.     stepper.move(-200*MICROSTEPS);
  62.  
  63.     // pause and allow the motor to be moved by hand
  64.     // stepper.disable();
  65.  
  66.     delay(5000);
  67. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement