Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* 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 21:31:32
- - Source Code generated by: Francesco Alessandro
- ********* Pleasedontcode.com **********/
- /****** DEFINITION OF LIBRARIES *****/
- #include <Arduino.h>
- #include <AccelStepper.h>
- /****** SYSTEM REQUIREMENT 1 *****/
- /* A stepper motor drives a 100mm length linear rail */
- /* slide. The motor performs 200 steps per */
- /* revolution. Each revolution moves the slide 10mm. */
- /****** SYSTEM REQUIREMENT 2 *****/
- /* Perform a complete travel from right to left in 12 */
- /* hours. Then perform a complete travel from left to */
- /* right of other 12 hours. */
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t stepper_A4988StepperMotorDriver_STEP_PIN_D8 = 8;
- const uint8_t stepper_A4988StepperMotorDriver_DIR_PIN_D9 = 9;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- AccelStepper stepper(AccelStepper::DRIVER, stepper_A4988StepperMotorDriver_STEP_PIN_D8, stepper_A4988StepperMotorDriver_DIR_PIN_D9);
- void setup(void)
- {
- // Set the maximum speed and acceleration of the stepper motor
- stepper.setMaxSpeed(100);
- stepper.setAcceleration(100);
- }
- void loop(void)
- {
- // Move the stepper motor to a specific position
- stepper.moveTo(2000); // Move the slide 100mm (10mm per revolution * 200 steps per revolution)
- // Run the stepper motor until it reaches the target position
- while (stepper.distanceToGo() != 0) {
- stepper.run();
- }
- // Delay for 12 hours
- delay(12 * 60 * 60 * 1000);
- // Move the stepper motor to a different position
- stepper.moveTo(0); // Move the slide back to the starting position
- // Run the stepper motor until it reaches the target position
- while (stepper.distanceToGo() != 0) {
- stepper.run();
- }
- // Delay for 12 hours
- delay(12 * 60 * 60 * 1000);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement