Advertisement
pleasedontcode

LinearRailSlide rev_76

Nov 29th, 2023
91
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:13:50
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /********* User code review feedback **********
  20. #### Feedback 1 ####
  21. - provide another algorithm.
  22. ********* User code review feedback **********/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <Stepper.h>
  27.  
  28. /****** SYSTEM REQUIREMENT 1 *****/
  29. /* A stepper motor drives a 200 mm length linear rail */
  30. /* slide. The motor performs 100 steps/revolution. */
  31. /* Step per mm of Lead screw is 10mm. */
  32. /****** SYSTEM REQUIREMENT 2 *****/
  33. /* Perform a complete continuous travel from right to */
  34. /* left in 12 hour. Then go back from left to right */
  35. /* again in 12 hours. The movement shall be */
  36. /* continuous in 12 hours. Do not use delay function. */
  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. Stepper myStepper(100, STEPPER_PIN_1_PIN_D2, STEPPER_PIN_2_PIN_D3, STEPPER_PIN_3_PIN_D4, STEPPER_PIN_4_PIN_D5);
  50.  
  51. void setup(void)
  52. {
  53.   // put your setup code here, to run once:
  54.   pinMode(STEPPER_PIN_1_PIN_D2, OUTPUT);
  55.   pinMode(STEPPER_PIN_2_PIN_D3, OUTPUT);
  56.   pinMode(STEPPER_PIN_3_PIN_D4, OUTPUT);
  57.   pinMode(STEPPER_PIN_4_PIN_D5, OUTPUT);
  58. }
  59.  
  60. void loop(void)
  61. {
  62.   // put your main code here, to run repeatedly:
  63.   unsigned long startTime = millis(); // Start time of the 12-hour cycle
  64.   unsigned long currentTime = 0; // Current time in the 12-hour cycle
  65.   unsigned long elapsedTime = 0; // Elapsed time since the start of the cycle
  66.   int direction = 1; // Direction of movement (1 for right to left, -1 for left to right)
  67.  
  68.   while (elapsedTime <= 12 * 60 * 60 * 1000) // Run for 12 hours
  69.   {
  70.     currentTime = millis() - startTime; // Calculate current time
  71.     elapsedTime = currentTime % (12 * 60 * 60 * 1000); // Calculate elapsed time
  72.  
  73.     myStepper.step(direction); // Move the stepper motor one step
  74.     delayMicroseconds(1000); // Delay for 1 millisecond
  75.   }
  76.  
  77.   // Reverse direction after 12 hours
  78.   direction = -direction;
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement