Advertisement
pleasedontcode

LinearRailSlide rev_64

Nov 29th, 2023
78
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: LinearRailSlide
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2023-11-29 21:29:17
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <AccelStepper.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* A stepper motor drives a 100mm length linear rail */
  24. /* slide. The motor performs 200 steps per */
  25. /* revolution. Each revolution moves the slide 10mm. */
  26. /****** SYSTEM REQUIREMENT 2 *****/
  27. /* Perform a complete travel from right to left in 12 */
  28. /* hours. Then perform a complete travel from left to */
  29. /* right of other 12 hours. */
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  36. const uint8_t stepper_A4988StepperMotorDriver_STEP_PIN_D8 = 8;
  37. const uint8_t stepper_A4988StepperMotorDriver_DIR_PIN_D9 = 9;
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  40. AccelStepper stepper(1, stepper_A4988StepperMotorDriver_STEP_PIN_D8, stepper_A4988StepperMotorDriver_DIR_PIN_D9);
  41.  
  42. void setup(void)
  43. {
  44.     // put your setup code here, to run once:
  45.     pinMode(stepper_A4988StepperMotorDriver_STEP_PIN_D8, OUTPUT);
  46.     pinMode(stepper_A4988StepperMotorDriver_DIR_PIN_D9, OUTPUT);
  47.  
  48.     stepper.setMaxSpeed(200.0);
  49.     stepper.setAcceleration(100.0);
  50.     stepper.moveTo(2000); // Move the stepper motor 2000 steps
  51. }
  52.  
  53. void loop(void)
  54. {
  55.     // put your main code here, to run repeatedly:
  56.     stepper.run();
  57.  
  58.     if (stepper.distanceToGo() == 0) {
  59.         // Reverse the direction when the stepper motor reaches the target position
  60.         stepper.moveTo(-stepper.currentPosition());
  61.     }
  62.  
  63.     delay(1);
  64. }
  65.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement