Advertisement
pleasedontcode

"Servo Control" rev_01

Jun 20th, 2024
518
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 NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-06-20 17:49:26
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* szervó motor seriallal való vezérlése */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /****** DEFINITION OF LIBRARIES *****/
  24. #include <Servo.h>  //https://github.com/arduino-libraries/Servo
  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 motor_Servomotor_PWMSignal_PIN_D3 = 3;
  33.  
  34. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  35. /***** used to store raw data *****/
  36. uint8_t motor_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  37.  
  38. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  39. /***** used to store data after characteristic curve transformation *****/
  40. float motor_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  41.  
  42. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  43. Servo myservo;  // Create a Servo object
  44.  
  45. void setup(void)
  46. {
  47.     // put your setup code here, to run once:
  48.     myservo.attach(motor_Servomotor_PWMSignal_PIN_D3);  // Attach the servo to pin 3
  49.     pinMode(motor_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  50.     Serial.begin(9600);  // Initialize serial communication at 9600 bits per second
  51. }
  52.  
  53. void loop(void)
  54. {
  55.     // put your main code here, to run repeatedly:
  56.     if (Serial.available() > 0) {
  57.         int input = Serial.parseInt();  // Read the incoming integer from the serial buffer
  58.         if (input >= 0 && input <= 180) {
  59.             motor_Servomotor_PWMSignal_PIN_D3_rawData = input;  // Update the raw data with the received value
  60.         }
  61.     }
  62.     updateOutputs(); // Refresh output data
  63. }
  64.  
  65. void updateOutputs()
  66. {
  67.     myservo.write(motor_Servomotor_PWMSignal_PIN_D3_rawData);  // Write the raw data to the servo
  68.     delay(15);  // Small delay to allow the servo to move
  69. }
  70.  
  71. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement