Advertisement
pleasedontcode

"Stepper Control" rev_01

Jan 5th, 2024
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: "Stepper Control"
  13.     - Source Code compiled for: Arduino Mega
  14.     - Source Code created on: 2024-01-05 12:37:53
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* speed of motor will be 500, motor will do 3 */
  21.     /* rotation then 2 sec delay then 3 rotation then */
  22.     /* delay then 3 rotation then delay then 3 rotation */
  23.     /* then 11 rotation with high speed */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Arduino.h>
  28. #include <AccelStepper.h>
  29.  
  30. /****** SYSTEM REQUIREMENTS *****/
  31. // Speed of motor will be 500, motor will do 3 rotations then 2 sec delay then 3 rotations then delay then 3 rotations then 11 rotations with high speed
  32. const float rotationSpeed = 500.0;
  33. const int numRotations = 3;
  34. const int delayTime = 2000;
  35. const int highSpeedRotations = 11;
  36.  
  37. /****** FUNCTION PROTOTYPES *****/
  38. void setup(void);
  39. void loop(void);
  40.  
  41. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  42. const uint8_t driver_A4988StepperMotorDriver_STEP_PIN_D8 = 8;
  43. const uint8_t driver_A4988StepperMotorDriver_DIR_PIN_D9 = 9;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. AccelStepper stepper1;
  47. AccelStepper stepper2(AccelStepper::FULL4WIRE, 6, 7, 8, 9);
  48. AccelStepper stepper3(AccelStepper::FULL2WIRE, 10, 11);
  49.  
  50. void setup(void)
  51. {
  52.     // put your setup code here, to run once:
  53.     pinMode(driver_A4988StepperMotorDriver_STEP_PIN_D8, OUTPUT);
  54.     pinMode(driver_A4988StepperMotorDriver_DIR_PIN_D9, OUTPUT);
  55.  
  56.     stepper1.setMaxSpeed(rotationSpeed);
  57.     stepper1.setAcceleration(100.0);
  58.     stepper1.moveTo(numRotations * 200); // 3 rotations
  59.  
  60.     stepper2.setMaxSpeed(rotationSpeed);
  61.     stepper2.setAcceleration(100.0);
  62.     stepper2.moveTo(numRotations * 200); // 3 rotations
  63.  
  64.     stepper3.setMaxSpeed(rotationSpeed);
  65.     stepper3.setAcceleration(100.0);
  66.     stepper3.moveTo(numRotations * 200); // 3 rotations
  67. }
  68.  
  69. void loop(void)
  70. {
  71.     // put your main code here, to run repeatedly:
  72.     if (stepper1.distanceToGo() == 0)
  73.     {
  74.         delay(delayTime); // 2 seconds delay
  75.         stepper1.moveTo(numRotations * 200); // 3 rotations
  76.     }
  77.     stepper1.run();
  78.     stepper2.run();
  79.     stepper3.run();
  80.  
  81.     // High speed rotation
  82.     if (stepper1.currentPosition() >= numRotations * 200)
  83.     {
  84.         stepper1.setMaxSpeed(1000.0);
  85.         stepper1.moveTo(highSpeedRotations * 200); // 11 rotations
  86.     }
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement