/********* Pleasedontcode.com ********** Pleasedontcode thanks you for automatic code generation! Enjoy your code! - Terms and Conditions: You have a non-exclusive, revocable, worldwide, royalty-free license for personal and commercial use. Attribution is optional; modifications are allowed, but you're responsible for code maintenance. We're not liable for any loss or damage. For full terms, please visit pleasedontcode.com/termsandconditions. - Project: LinearRailSlide - Source Code compiled for: Arduino Uno - Source Code created on: 2023-11-29 22:07:35 - Source Code generated by: Francesco Alessandro ********* Pleasedontcode.com **********/ /********* User code review feedback ********** #### Feedback 1 #### - do not block code with delay. ********* User code review feedback **********/ /****** DEFINITION OF LIBRARIES *****/ #include #include /****** SYSTEM REQUIREMENT 1 *****/ /* Perform a complete continuous travel from right to */ /* left in 12 hours. Then go back from left to right */ /* again in 12 hours. The movement shall be */ /* continuous in 12 hours. Do not use delay function. */ /****** SYSTEM REQUIREMENT 2 *****/ /* A stepper motor drives a 200 mm length linear rail */ /* slide. The motor performs 100 steps/revolution. */ /* Step per mm of Lead screw is 10mm. */ /****** FUNCTION PROTOTYPES *****/ void setup(void); void loop(void); /***** DEFINITION OF DIGITAL OUTPUT PINS *****/ const uint8_t STEPPER_PIN_1_PIN_D2 = 2; const uint8_t STEPPER_PIN_2_PIN_D3 = 3; const uint8_t STEPPER_PIN_3_PIN_D4 = 4; const uint8_t STEPPER_PIN_4_PIN_D5 = 5; /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/ Stepper myStepper(100, STEPPER_PIN_1_PIN_D2, STEPPER_PIN_2_PIN_D3, STEPPER_PIN_3_PIN_D4, STEPPER_PIN_4_PIN_D5); void setup(void) { // put your setup code here, to run once: pinMode(STEPPER_PIN_1_PIN_D2, OUTPUT); pinMode(STEPPER_PIN_2_PIN_D3, OUTPUT); pinMode(STEPPER_PIN_3_PIN_D4, OUTPUT); pinMode(STEPPER_PIN_4_PIN_D5, OUTPUT); } void loop(void) { // put your main code here, to run repeatedly: /****** SYSTEM REQUIREMENT 1 *****/ /* Complete continuous travel from right to left in 12 hours */ unsigned long startTime = millis(); while (millis() - startTime < 12 * 60 * 60 * 1000) { myStepper.step(1); // Move one step clockwise } /* Go back from left to right again in 12 hours */ startTime = millis(); while (millis() - startTime < 12 * 60 * 60 * 1000) { myStepper.step(-1); // Move one step counterclockwise } /****** SYSTEM REQUIREMENT 2 *****/ /* Calculate number of steps required to move 200 mm */ int stepsPerRevolution = 100; int mmPerRevolution = 10; float stepsPerMM = stepsPerRevolution / mmPerRevolution; int stepsToMove = stepsPerMM * 200; /* Move the stepper motor to slide the linear rail */ for (int i = 0; i < stepsToMove; i++) { myStepper.step(1); // Move one step clockwise } delay(1000); // Wait for 1 second before the next movement }