Advertisement
pleasedontcode

motor_test

Apr 2nd, 2024
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Arduino 2.39 KB | Source Code | 0 0
  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: motor_test
  13.     - Source Code created on: 2024-04-01 14:25:47
  14.  
  15. ********* Pleasedontcode.com **********/
  16.  
  17. /****** SYSTEM REQUIREMENTS *****/
  18. /****** SYSTEM REQUIREMENT 1 *****/
  19.     /* turn 180 degrees then disable motor */
  20. /****** END SYSTEM REQUIREMENTS *****/
  21.  
  22. /****** DEFINITION OF LIBRARIES *****/
  23. #include <Servo.h> // Servo library for the servo motor
  24. #include <TinyStepper_28BYJ_48.h> // Stepper library for the stepper motor
  25.  
  26. /****** FUNCTION PROTOTYPES *****/
  27. void setup(void);
  28. void loop(void);
  29. void updateOutputs(void);
  30.  
  31. /***** DEFINITION OF PWM OUTPUT PINS *****/
  32. const uint8_t motor1_Servomotor_PWMSignal_PIN_D3 = 3;
  33.  
  34. /***** DEFINITION OF STEPPER OUTPUT PINS *****/
  35. const int MOTOR_IN1_PIN = 11;
  36. const int MOTOR_IN2_PIN = 10;
  37. const int MOTOR_IN3_PIN = 6;
  38. const int MOTOR_IN4_PIN = 5;
  39.  
  40. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  41. /***** used to store raw data *****/
  42. uint8_t motor1_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  43.  
  44. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  45. /***** used to store data after characteristic curve transformation *****/
  46. float motor1_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  47.  
  48. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  49. Servo motor1_Servomotor;
  50. TinyStepper_28BYJ_48 stepper; // Instantiate the stepper object
  51.  
  52. void setup(void) {
  53.   // put your setup code here, to run once:
  54.   motor1_Servomotor.attach(motor1_Servomotor_PWMSignal_PIN_D3);
  55.  
  56.   stepper.connectToPins(MOTOR_IN1_PIN, MOTOR_IN2_PIN, MOTOR_IN3_PIN, MOTOR_IN4_PIN); // Connect the stepper motor to the pins
  57. }
  58.  
  59. void loop(void) {
  60.   // put your main code here, to run repeatedly:
  61.   updateOutputs(); // Refresh output data
  62.  
  63.   // System Requirement 1: Turn 180 degrees then disable motor
  64.   motor1_Servomotor.write(180);
  65.   delay(1000);
  66.   motor1_Servomotor.detach();
  67.  
  68.   // Add your stepper motor code here
  69. }
  70.  
  71. void updateOutputs() {
  72.   motor1_Servomotor.write(motor1_Servomotor_PWMSignal_PIN_D3_rawData);
  73. }
  74.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement