Advertisement
pleasedontcode

Arduino Robotics rev_02

May 20th, 2024
1,043
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: Arduino Robotics
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2024-05-20 22:36:14
  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. /****** DEFINITION OF LIBRARIES *****/
  27. #include <Servo.h>  // https://github.com/arduino-libraries/Servo
  28. #include <Ultrasonic.h>  // https://github.com/ErickSimoes/Ultrasonic
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs(void);
  34.  
  35. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  36. const uint8_t h1_HC_SR04_Echo_PIN_D4 = 4;
  37.  
  38. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  39. const uint8_t h1_HC_SR04_Trigger_PIN_D2 = 2;
  40.  
  41. /***** DEFINITION OF PWM OUTPUT PINS *****/
  42. const uint8_t myservo_Servomotor_PWMSignal_PIN_D3 = 3;
  43.  
  44. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  45. /***** used to store raw data *****/
  46. bool h1_HC_SR04_Trigger_PIN_D2_rawData = 0;
  47. uint8_t myservo_Servomotor_PWMSignal_PIN_D3_rawData = 0;
  48.  
  49. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  50. /***** used to store data after characteristic curve transformation *****/
  51. float h1_HC_SR04_Trigger_PIN_D2_phyData = 0.0;
  52. float myservo_Servomotor_PWMSignal_PIN_D3_phyData = 0.0;
  53.  
  54. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  55. Servo myservo; // Initialize Servo object
  56. Ultrasonic ultrasonic(12, 13); // Initialize Ultrasonic object with trigger pin 12 and echo pin 13
  57.  
  58. void setup(void)
  59. {
  60.     // put your setup code here, to run once:
  61.     pinMode(h1_HC_SR04_Echo_PIN_D4, INPUT);
  62.     pinMode(h1_HC_SR04_Trigger_PIN_D2, OUTPUT);
  63.     pinMode(myservo_Servomotor_PWMSignal_PIN_D3, OUTPUT);
  64.  
  65.     myservo.attach(myservo_Servomotor_PWMSignal_PIN_D3); // Attach Servo to the PWM pin
  66. }
  67.  
  68. void loop(void)
  69. {
  70.     // put your main code here, to run repeatedly:
  71.     updateOutputs(); // Refresh output data
  72. }
  73.  
  74. void updateOutputs()
  75. {
  76.     digitalWrite(h1_HC_SR04_Trigger_PIN_D2, h1_HC_SR04_Trigger_PIN_D2_rawData);
  77.     analogWrite(myservo_Servomotor_PWMSignal_PIN_D3, myservo_Servomotor_PWMSignal_PIN_D3_rawData);
  78. }
  79.  
  80. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement