CCCPaste

Stepper Control rev_01

/********* 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 Uno
	- Source Code created on: 2024-03-19 17:51:46

********* Pleasedontcode.com **********/

/****** SYSTEM REQUIREMENTS *****/
/****** SYSTEM REQUIREMENT 1 *****/
	/* run stepper motor with variable speed control */
	/* using 10k pot */
/****** END SYSTEM REQUIREMENTS *****/

/****** DEFINITION OF LIBRARIES *****/
#include 

/****** FUNCTION PROTOTYPES *****/
void setup(void);
void loop(void);
void updateOutputs(void);

/***** DEFINITION OF DIGITAL OUTPUT PINS *****/
const uint8_t Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4 = 4;
const uint8_t Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5 = 5;

/***** DEFINITION OF OUTPUT RAW VARIABLES *****/
/***** used to store raw data *****/
bool Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4_rawData = 0;
bool Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5_rawData = 0;

/***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
/***** used to store data after characteristic curve transformation *****/
float Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4_phyData = 0.0;
float Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5_phyData = 0.0;

/****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
AccelStepper stepper(AccelStepper::DRIVER, Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4, Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5);

void setup(void)
{
  // put your setup code here, to run once:
  pinMode(Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4, OUTPUT);
  pinMode(Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5, OUTPUT);
  stepper.setMaxSpeed(1000);
}

void loop(void)
{
  // put your main code here, to run repeatedly:
  int analog_in = analogRead(A0); // Read analog input from potentiometer
  stepper.moveTo(analog_in); // Set the target position for the stepper motor
  stepper.setSpeed(100); // Set the speed of the stepper motor
  stepper.runSpeedToPosition(); // Run the stepper motor to reach the target position
  updateOutputs(); // Refresh output data
}

void updateOutputs(void)
{
  digitalWrite(Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4, Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4_rawData);
  digitalWrite(Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5, Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5_rawData);
}