Advertisement
pleasedontcode

"Servo Control" rev_01

Mar 19th, 2024
30
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: "Servo Control"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-03-19 10:06:38
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* turns off the motor slowly if the speed level */
  21.     /* exceeds above 300000 kmph */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Servo.h> // Include Servo library
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs(void); // Declare updateOutputs function
  31.  
  32. /***** DEFINITION OF PWM OUTPUT PINS *****/
  33. const uint8_t motor_Servomotor_PWMSignal_PIN_D3 = 3;
  34.  
  35. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  36. /***** used to store raw data *****/
  37. uint8_t motor_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  38.  
  39. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  40. /***** used to store data after characteristic curve transformation *****/
  41. float motor_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  42.  
  43. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  44. Servo myservo; // Create Servo object
  45.  
  46. void setup(void)
  47. {
  48.   // put your setup code here, to run once:
  49.  
  50.   pinMode(motor_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  51.   myservo.attach(motor_Servomotor_PWMSignal_PIN_D3); // Attach Servo object to the pin
  52.  
  53. }
  54.  
  55. void loop(void)
  56. {
  57.   // put your main code here, to run repeatedly:
  58.  
  59.   /****** SYSTEM REQUIREMENTS *****/
  60.   /****** SYSTEM REQUIREMENT 1 *****/
  61.   /* turns off the motor slowly if the speed level */
  62.   /* exceeds above 300000 kmph */
  63.  
  64.   if(motor_Servomotor_PWMSignal_PIN_D3_rawData > 300000) {
  65.     motor_Servomotor_PWMSignal_PIN_D3_rawData = 180; // Set the servo position to maximum (turn off slowly)
  66.   }
  67.  
  68.   updateOutputs(); // Refresh output data
  69.  
  70. }
  71.  
  72. void updateOutputs()
  73. {
  74.   motor_Servomotor_PWMSignal_PIN_D3_phyData = motor_Servomotor_PWMSignal_PIN_D3_rawData / 1023.0 * 180.0; // Transform raw data to physical data
  75.   myservo.write(motor_Servomotor_PWMSignal_PIN_D3_phyData); // Use Servo object to set the position
  76. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement