Advertisement
pleasedontcode

LinearRailSlide rev_79

Nov 29th, 2023
87
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 22:20:26
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <Stepper.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* A stepper motor drives a 200 mm length linear rail */
  24. /* slide. The motor performs 100 steps/revolution. */
  25. /* Step per mm of Lead screw is 10mm. */
  26. /****** SYSTEM REQUIREMENT 2 *****/
  27. /* Perform a complete continuous travel of 200mm from */
  28. /* right to left in 12 hours. Then go back from left */
  29. /* to right again in 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_PIN_1_PIN_D2 = 2;
  37. const uint8_t STEPPER_PIN_2_PIN_D3 = 3;
  38. const uint8_t STEPPER_PIN_3_PIN_D4 = 4;
  39. const uint8_t STEPPER_PIN_4_PIN_D5 = 5;
  40.  
  41. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  42. const int stepsPerRevolution = 100;
  43. Stepper myStepper(stepsPerRevolution, STEPPER_PIN_1_PIN_D2, STEPPER_PIN_2_PIN_D3, STEPPER_PIN_3_PIN_D4, STEPPER_PIN_4_PIN_D5);
  44.  
  45. void setup(void)
  46. {
  47.     // put your setup code here, to run once:
  48.     pinMode(STEPPER_PIN_1_PIN_D2, OUTPUT);
  49.     pinMode(STEPPER_PIN_2_PIN_D3, OUTPUT);
  50.     pinMode(STEPPER_PIN_3_PIN_D4, OUTPUT);
  51.     pinMode(STEPPER_PIN_4_PIN_D5, OUTPUT);
  52. }
  53.  
  54. void loop(void)
  55. {
  56.     // put your main code here, to run repeatedly:
  57.     // Perform a complete continuous travel of 200mm from right to left in 12 hours
  58.     for (int i = 0; i < 200; i++)
  59.     {
  60.         myStepper.setSpeed(100); // Set the speed of the stepper motor (adjust as needed)
  61.         myStepper.step(10); // Move the stepper motor 10 steps (equivalent to 1mm)
  62.         delay(43200000); // Delay for 12 hours (adjust as needed)
  63.     }
  64.  
  65.     // Go back from left to right again in 12 hours
  66.     for (int i = 0; i < 200; i++)
  67.     {
  68.         myStepper.setSpeed(100); // Set the speed of the stepper motor (adjust as needed)
  69.         myStepper.step(-10); // Move the stepper motor 10 steps backwards (equivalent to 1mm)
  70.         delay(43200000); // Delay for 12 hours (adjust as needed)
  71.     }
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement