/********* 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: "Stepper Control"
- Source Code compiled for: Arduino Mega
- Source Code created on: 2024-01-05 12:37:53
********* Pleasedontcode.com **********/
/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
/* speed of motor will be 500, motor will do 3 */
/* rotation then 2 sec delay then 3 rotation then */
/* delay then 3 rotation then delay then 3 rotation */
/* then 11 rotation with high speed */
/****** END SYSTEM REQUIREMENTS *****/
/****** DEFINITION OF LIBRARIES *****/
#include
#include
/****** SYSTEM REQUIREMENTS *****/
// Speed of motor will be 500, motor will do 3 rotations then 2 sec delay then 3 rotations then delay then 3 rotations then 11 rotations with high speed
const float rotationSpeed = 500.0;
const int numRotations = 3;
const int delayTime = 2000;
const int highSpeedRotations = 11;
/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t driver_A4988StepperMotorDriver_STEP_PIN_D8 = 8;
const uint8_t driver_A4988StepperMotorDriver_DIR_PIN_D9 = 9;
/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
AccelStepper stepper1;
AccelStepper stepper2(AccelStepper::FULL4WIRE, 6, 7, 8, 9);
AccelStepper stepper3(AccelStepper::FULL2WIRE, 10, 11);
void setup(void)
{
// put your setup code here, to run once:
pinMode(driver_A4988StepperMotorDriver_STEP_PIN_D8, OUTPUT);
pinMode(driver_A4988StepperMotorDriver_DIR_PIN_D9, OUTPUT);
stepper1.setMaxSpeed(rotationSpeed);
stepper1.setAcceleration(100.0);
stepper1.moveTo(numRotations * 200); // 3 rotations
stepper2.setMaxSpeed(rotationSpeed);
stepper2.setAcceleration(100.0);
stepper2.moveTo(numRotations * 200); // 3 rotations
stepper3.setMaxSpeed(rotationSpeed);
stepper3.setAcceleration(100.0);
stepper3.moveTo(numRotations * 200); // 3 rotations
}
void loop(void)
{
// put your main code here, to run repeatedly:
if (stepper1.distanceToGo() == 0)
{
delay(delayTime); // 2 seconds delay
stepper1.moveTo(numRotations * 200); // 3 rotations
}
stepper1.run();
stepper2.run();
stepper3.run();
// High speed rotation
if (stepper1.currentPosition() >= numRotations * 200)
{
stepper1.setMaxSpeed(1000.0);
stepper1.moveTo(highSpeedRotations * 200); // 11 rotations
}
}