Advertisement
pleasedontcode

Servo Control rev_03

May 20th, 2024
2,869
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-05-20 22:38:34
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Arduino pid code to keep the ball in the middle of */
  21.     /* the bar in the beam and ball control system so */
  22.     /* that the length of the beam is 32 cm and the */
  23.     /* ultrasonic sensor and 360 degree servo motor . */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26.  
  27. /****** DEFINITION OF LIBRARIES *****/
  28. #include <Servo.h>  // https://github.com/arduino-libraries/Servo
  29. #include <Ultrasonic.h>  // https://github.com/ErickSimoes/Ultrasonic
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs(void);
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t h1_HC_SR04_Echo_PIN_D4 = 4;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t h1_HC_SR04_Trigger_PIN_D2 = 2;
  41.  
  42. /***** DEFINITION OF PWM OUTPUT PINS *****/
  43. const uint8_t myservo_Servomotor_PWMSignal_PIN_D3 = 3;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. /***** used to store raw data *****/
  47. bool h1_HC_SR04_Trigger_PIN_D2_rawData = 0;
  48. uint8_t myservo_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  49.  
  50. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  51. /***** used to store data after characteristic curve transformation *****/
  52. float h1_HC_SR04_Trigger_PIN_D2_phyData = 0.0;
  53. float myservo_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  54.  
  55. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  56. Servo myservo; // Initialize Servo object
  57. Ultrasonic ultrasonic(12, 13); // Initialize Ultrasonic object with trigger pin 12 and echo pin 13
  58.  
  59. void setup(void)
  60. {
  61.     // put your setup code here, to run once:
  62.     pinMode(h1_HC_SR04_Echo_PIN_D4, INPUT);
  63.     pinMode(h1_HC_SR04_Trigger_PIN_D2, OUTPUT);
  64.     pinMode(myservo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  65.  
  66.     myservo.attach(myservo_Servomotor_PWMSignal_PIN_D3); // Attach Servo to the PWM pin
  67. }
  68.  
  69. void loop(void)
  70. {
  71.     // put your main code here, to run repeatedly:
  72.     updateOutputs(); // Refresh output data
  73. }
  74.  
  75. void updateOutputs()
  76. {
  77.     digitalWrite(h1_HC_SR04_Trigger_PIN_D2, h1_HC_SR04_Trigger_PIN_D2_rawData);
  78.     analogWrite(myservo_Servomotor_PWMSignal_PIN_D3, myservo_Servomotor_PWMSignal_PIN_D3_rawData);
  79. }
  80.  
  81. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement