Advertisement
pleasedontcode

LinearRailSlide rev_66

Nov 29th, 2023
85
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 21:37:17
  15.     - Source Code generated by: Francesco Alessandro
  16.  
  17. ********* Pleasedontcode.com **********/
  18. /****** DEFINITION OF LIBRARIES *****/
  19. #include <Arduino.h>
  20. #include <AccelStepper.h>
  21.  
  22. /****** SYSTEM REQUIREMENT 1 *****/
  23. /* A stepper motor drives a 100mm length linear rail */
  24. /* slide. The motor performs 200 steps per */
  25. /* revolution. Each revolution moves the slide 10mm. */
  26. /****** SYSTEM REQUIREMENT 2 *****/
  27. /* Perform a complete continuous travel from right to */
  28. /* left in 12 hour. Then go back from left to right */
  29. /* again in 12 hours. The movement shall be */
  30. /* continuous in 12 hours. */
  31.  
  32. /****** FUNCTION PROTOTYPES *****/
  33. void setup(void);
  34. void loop(void);
  35.  
  36. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  37. const uint8_t stepper_A4988StepperMotorDriver_STEP_PIN_D8 = 8;
  38. const uint8_t stepper_A4988StepperMotorDriver_DIR_PIN_D9 = 9;
  39.  
  40. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  41. AccelStepper stepper(AccelStepper::DRIVER, stepper_A4988StepperMotorDriver_STEP_PIN_D8, stepper_A4988StepperMotorDriver_DIR_PIN_D9);
  42.  
  43. void setup(void)
  44. {
  45.   // put your setup code here, to run once:
  46.  
  47.   pinMode(stepper_A4988StepperMotorDriver_STEP_PIN_D8, OUTPUT);
  48.   pinMode(stepper_A4988StepperMotorDriver_DIR_PIN_D9, OUTPUT);
  49.  
  50.   stepper.setMaxSpeed(100);
  51. }
  52.  
  53. void loop(void)
  54. {
  55.   // put your main code here, to run repeatedly:
  56.  
  57.   // Move the stepper motor to position 1000
  58.   stepper.moveTo(1000);
  59.   stepper.runSpeedToPosition();
  60.   delay(1000);
  61.  
  62.   // Move the stepper motor to position -100
  63.   stepper.moveTo(-100);
  64.   stepper.runSpeedToPosition();
  65.   delay(1000);
  66. }
  67.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement