Advertisement
pleasedontcode

LinearRailSlide rev_71

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:01:09
  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. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  34. const uint8_t STEPPER_PIN_1 = 2;
  35. const uint8_t STEPPER_PIN_2 = 3;
  36. const uint8_t STEPPER_PIN_3 = 4;
  37. const uint8_t STEPPER_PIN_4 = 5;
  38.  
  39. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  40. Stepper myStepper(100, STEPPER_PIN_1, STEPPER_PIN_3, STEPPER_PIN_2, STEPPER_PIN_4);
  41.  
  42. void setup(void)
  43. {
  44.   // put your setup code here, to run once:
  45.   pinMode(STEPPER_PIN_1, OUTPUT);
  46.   pinMode(STEPPER_PIN_2, OUTPUT);
  47.   pinMode(STEPPER_PIN_3, OUTPUT);
  48.   pinMode(STEPPER_PIN_4, OUTPUT);
  49. }
  50.  
  51. void loop(void)
  52. {
  53.   // put your main code here, to run repeatedly:
  54.  
  55.   // Add your code for the stepper motor movement
  56.  
  57.   /* Add code for continuous travel from right to left for 12 hours */
  58.   /* Note: Do not use delay function */
  59.  
  60.   for (int i = 0; i < 12000; i++) {
  61.     myStepper.step(100);
  62.     delay(1); // 1ms delay between steps to achieve continuous movement for 12 hours
  63.   }
  64.  
  65.   /* Add code for continuous travel from left to right for 12 hours */
  66.   /* Note: Do not use delay function */
  67.  
  68.   for (int i = 0; i < 12000; i++) {
  69.     myStepper.step(-100);
  70.     delay(1); // 1ms delay between steps to achieve continuous movement for 12 hours
  71.   }
  72. }
  73.  
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement