Advertisement
pleasedontcode

Servo Control rev_01

Jul 25th, 2024
221
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: ESP32 DevKit V1
  14.     - Source Code created on: 2024-07-25 11:10:03
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* stworz konsole w ktorej bedzie polecenie dzieki */
  21.     /* ktoremu moge sterowac servo */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /****** DEFINITION OF LIBRARIES *****/
  25. #include <Deneyap_Servo.h>  //https://github.com/deneyapkart/deneyap-servo-arduino-library
  26.  
  27. /****** FUNCTION PROTOTYPES *****/
  28. void setup(void);
  29. void loop(void);
  30. void updateOutputs(void);
  31.  
  32. /***** DEFINITION OF PWM OUTPUT PINS *****/
  33. const uint8_t servo_Servomotor_PWMSignal_PIN_D4     = 4;
  34. const uint8_t servo_Servomotor_PWMSignal_PIN_D13        = 13;
  35.  
  36. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  37. /***** used to store raw data *****/
  38. uint8_t servo_Servomotor_PWMSignal_PIN_D4_rawData       = 0;
  39. uint8_t servo_Servomotor_PWMSignal_PIN_D13_rawData      = 0;
  40.  
  41. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  42. /***** used to store data after characteristic curve transformation *****/
  43. float   servo_Servomotor_PWMSignal_PIN_D4_phyData       = 0.0;
  44. float   servo_Servomotor_PWMSignal_PIN_D13_phyData      = 0.0;
  45.  
  46. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  47. // Create Servo objects for each PWM signal pin
  48. Deneyap_Servo servo1; // For pin D4
  49. Deneyap_Servo servo2; // For pin D13
  50.  
  51. void setup(void)
  52. {
  53.     // Initialize serial communication for console commands
  54.     Serial.begin(9600); // Start serial communication at 9600 baud rate
  55.  
  56.     // Attach the servo objects to their respective pins
  57.     servo1.attach(servo_Servomotor_PWMSignal_PIN_D4);
  58.     servo2.attach(servo_Servomotor_PWMSignal_PIN_D13);
  59.  
  60.     pinMode(servo_Servomotor_PWMSignal_PIN_D4,   OUTPUT);
  61.     pinMode(servo_Servomotor_PWMSignal_PIN_D13,  OUTPUT);
  62. }
  63.  
  64. void loop(void)
  65. {
  66.     // Check if data is available to read from the Serial Monitor
  67.     if (Serial.available() > 0) {
  68.         // Read the input value from the Serial Monitor
  69.         int angle = Serial.parseInt(); // Parse the integer value
  70.  
  71.         // Ensure the angle is within the valid range for the servo
  72.         if (angle >= 0 && angle <= 180) {
  73.             // Update raw data for both servos
  74.             servo_Servomotor_PWMSignal_PIN_D4_rawData = angle; // Set angle for servo1
  75.             servo_Servomotor_PWMSignal_PIN_D13_rawData = angle; // Set angle for servo2
  76.         } else {
  77.             Serial.println("Invalid angle! Please enter a value between 0 and 180.");
  78.         }
  79.     }
  80.  
  81.     updateOutputs(); // Refresh output data
  82. }
  83.  
  84. void updateOutputs()
  85. {
  86.     // Write the raw data to the servo objects
  87.     servo1.write(servo_Servomotor_PWMSignal_PIN_D4_rawData);
  88.     servo2.write(servo_Servomotor_PWMSignal_PIN_D13_rawData);
  89. }
  90.  
  91. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement