Advertisement
pleasedontcode

LinearRailSlide rev_72

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:03:45
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18.  
  19. /********* User code review feedback **********
  20. #### Feedback 1 ####
  21. - complete the code in according to system requirements.
  22. ********* User code review feedback **********/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Arduino.h>
  26. #include <Stepper.h>
  27.  
  28. /****** SYSTEM REQUIREMENT 1 *****/
  29. /* Perform a complete continuous travel from right to */
  30. /* left in 12 hours. Then go back from left to right */
  31. /* again in 12 hours. The movement shall be */
  32. /* continuous in 12 hours. Do not use delay function. */
  33.  
  34. /****** SYSTEM REQUIREMENT 2 *****/
  35. /* A stepper motor drives a 200 mm length linear rail */
  36. /* slide. The motor performs 100 steps/revolution. */
  37. /* Step per mm of Lead screw is 10mm. */
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t STEPPER_PIN_1 = 2;
  41. const uint8_t STEPPER_PIN_2 = 3;
  42. const uint8_t STEPPER_PIN_3 = 4;
  43. const uint8_t STEPPER_PIN_4 = 5;
  44.  
  45. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  46. Stepper myStepper(100, STEPPER_PIN_1, STEPPER_PIN_3, STEPPER_PIN_2, STEPPER_PIN_4);
  47.  
  48. void setup(void)
  49. {
  50.   // put your setup code here, to run once:
  51.   pinMode(STEPPER_PIN_1, OUTPUT);
  52.   pinMode(STEPPER_PIN_2, OUTPUT);
  53.   pinMode(STEPPER_PIN_3, OUTPUT);
  54.   pinMode(STEPPER_PIN_4, OUTPUT);
  55. }
  56.  
  57. void loop(void)
  58. {
  59.   // put your main code here, to run repeatedly:
  60.  
  61.   // Add your code for the stepper motor movement
  62.  
  63.   /* Add code for continuous travel from right to left for 12 hours */
  64.   /* Note: Do not use delay function */
  65.  
  66.   unsigned long startTime = millis();
  67.   unsigned long elapsedTime = 0;
  68.  
  69.   while (elapsedTime < 12 * 60 * 60 * 1000) {
  70.     myStepper.step(100);
  71.     elapsedTime = millis() - startTime;
  72.   }
  73.  
  74.   /* Add code for continuous travel from left to right for 12 hours */
  75.   /* Note: Do not use delay function */
  76.  
  77.   startTime = millis();
  78.   elapsedTime = 0;
  79.  
  80.   while (elapsedTime < 12 * 60 * 60 * 1000) {
  81.     myStepper.step(-100);
  82.     elapsedTime = millis() - startTime;
  83.   }
  84. }
  85.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement