Advertisement
pleasedontcode

LinearRailSlide rev_65

Nov 29th, 2023
80
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:31:32
  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(AccelStepper::DRIVER, stepper_A4988StepperMotorDriver_STEP_PIN_D8, stepper_A4988StepperMotorDriver_DIR_PIN_D9);
  41.  
  42. void setup(void)
  43. {
  44.   // Set the maximum speed and acceleration of the stepper motor
  45.   stepper.setMaxSpeed(100);
  46.   stepper.setAcceleration(100);
  47. }
  48.  
  49. void loop(void)
  50. {
  51.   // Move the stepper motor to a specific position
  52.   stepper.moveTo(2000); // Move the slide 100mm (10mm per revolution * 200 steps per revolution)
  53.   // Run the stepper motor until it reaches the target position
  54.   while (stepper.distanceToGo() != 0) {
  55.     stepper.run();
  56.   }
  57.   // Delay for 12 hours
  58.   delay(12 * 60 * 60 * 1000);
  59.  
  60.   // Move the stepper motor to a different position
  61.   stepper.moveTo(0); // Move the slide back to the starting position
  62.   // Run the stepper motor until it reaches the target position
  63.   while (stepper.distanceToGo() != 0) {
  64.     stepper.run();
  65.   }
  66.   // Delay for 12 hours
  67.   delay(12 * 60 * 60 * 1000);
  68. }
  69.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement