Advertisement
pleasedontcode

LinearRailSlide rev_73

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 22:04:55
  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. /* Perform a complete continuous travel from right to */
  24. /* left in 12 hours. Then go back from left to right */
  25. /* again in 12 hours. The movement shall be */
  26. /* continuous in 12 hours. Do not use delay function. */
  27.  
  28. /****** SYSTEM REQUIREMENT 2 *****/
  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.  
  33. /****** FUNCTION PROTOTYPES *****/
  34. void setup(void);
  35. void loop(void);
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t STEPPER_PIN_1_PIN_D2 = 2;
  39. const uint8_t STEPPER_PIN_2_PIN_D3 = 3;
  40. const uint8_t STEPPER_PIN_3_PIN_D4 = 4;
  41. const uint8_t STEPPER_PIN_4_PIN_D5 = 5;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. Stepper myStepper(100, STEPPER_PIN_1_PIN_D2, STEPPER_PIN_2_PIN_D3, STEPPER_PIN_3_PIN_D4, STEPPER_PIN_4_PIN_D5);
  45.  
  46. void setup(void)
  47. {
  48.   // put your setup code here, to run once:
  49.   pinMode(STEPPER_PIN_1_PIN_D2, OUTPUT);
  50.   pinMode(STEPPER_PIN_2_PIN_D3, OUTPUT);
  51.   pinMode(STEPPER_PIN_3_PIN_D4, OUTPUT);
  52.   pinMode(STEPPER_PIN_4_PIN_D5, OUTPUT);
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // put your main code here, to run repeatedly:
  58.   /****** SYSTEM REQUIREMENT 1 *****/
  59.   /* Complete continuous travel from right to left in 12 hours */
  60.   for (int i = 0; i < (36000 * 2); i++) {
  61.     myStepper.step(1); // Move one step clockwise
  62.     delay(100); // Wait for 100 milliseconds before the next step
  63.   }
  64.  
  65.   /* Go back from left to right again in 12 hours */
  66.   for (int i = 0; i < (36000 * 2); i++) {
  67.     myStepper.step(-1); // Move one step counterclockwise
  68.     delay(100); // Wait for 100 milliseconds before the next step
  69.   }
  70.  
  71.   /****** SYSTEM REQUIREMENT 2 *****/
  72.   /* Calculate number of steps required to move 200 mm */
  73.   int stepsPerRevolution = 100;
  74.   int mmPerRevolution = 10;
  75.   float stepsPerMM = stepsPerRevolution / mmPerRevolution;
  76.   int stepsToMove = stepsPerMM * 200;
  77.  
  78.   /* Move the stepper motor to slide the linear rail */
  79.   myStepper.step(stepsToMove);
  80.   delay(1000); // Wait for 1 second before the next movement
  81. }
  82.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement