Advertisement
pleasedontcode

Stepper Control rev_01

Mar 19th, 2024
80
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: Stepper Control
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-19 17:51:46
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* run stepper motor with variable speed control */
  21.     /* using 10k pot */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <AccelStepper.h>
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs(void);
  31.  
  32. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  33. const uint8_t Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4 = 4;
  34. const uint8_t Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5 = 5;
  35.  
  36. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  37. /***** used to store raw data *****/
  38. bool Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4_rawData = 0;
  39. bool Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5_rawData = 0;
  40.  
  41. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  42. /***** used to store data after characteristic curve transformation *****/
  43. float Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4_phyData = 0.0;
  44. float Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5_phyData = 0.0;
  45.  
  46. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  47. AccelStepper stepper(AccelStepper::DRIVER, Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4, Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5);
  48.  
  49. void setup(void)
  50. {
  51.   // put your setup code here, to run once:
  52.   pinMode(Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4, OUTPUT);
  53.   pinMode(Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5, OUTPUT);
  54.   stepper.setMaxSpeed(1000);
  55. }
  56.  
  57. void loop(void)
  58. {
  59.   // put your main code here, to run repeatedly:
  60.   int analog_in = analogRead(A0); // Read analog input from potentiometer
  61.   stepper.moveTo(analog_in); // Set the target position for the stepper motor
  62.   stepper.setSpeed(100); // Set the speed of the stepper motor
  63.   stepper.runSpeedToPosition(); // Run the stepper motor to reach the target position
  64.   updateOutputs(); // Refresh output data
  65. }
  66.  
  67. void updateOutputs(void)
  68. {
  69.   digitalWrite(Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4, Stepdriver_A4988StepperMotorDriver_MS2_PIN_D4_rawData);
  70.   digitalWrite(Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5, Stepdriver_A4988StepperMotorDriver_MS3_PIN_D5_rawData);
  71. }
  72.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement