Advertisement
pleasedontcode

LinearRailSlide rev_80

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