Advertisement
pleasedontcode

"Ultrasonic Setup" rev_01

Apr 20th, 2024
75
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: "Ultrasonic Setup"
  13.     - Source Code compiled for: Arduino Uno
  14.     - Source Code created on: 2024-04-20 13:34:50
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Generate Arduino code to control a robot with the */
  21.     /* following features:  - Three ultrasonic sensors */
  22.     /* connected to pins trigPin1, echoPin1, trigPin2, */
  23.     /* echoPin2, trigPin3, and echoPin3.  - An infrared */
  24.     /* sensor connected to pin irpin.  - Four DC motors */
  25.     /* connec */
  26. /****** END SYSTEM REQUIREMENTS *****/
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <Ultrasonic.h> // Include the Ultrasonic library
  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 trigPin1 = 2;
  38. const uint8_t echoPin1 = 3;
  39. const uint8_t trigPin2 = 4;
  40. const uint8_t echoPin2 = 5;
  41. const uint8_t trigPin3 = 6;
  42. const uint8_t echoPin3 = 7;
  43. const uint8_t irPin = 8;
  44.  
  45. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  46. bool trigPin1_rawData = 0;
  47. bool trigPin2_rawData = 0;
  48. bool trigPin3_rawData = 0;
  49.  
  50. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  51. float trigPin1_phyData = 0.0;
  52. float trigPin2_phyData = 0.0;
  53. float trigPin3_phyData = 0.0;
  54.  
  55. /****** DEFINITION OF LIBRARY CLASS INSTANCES *****/
  56. Ultrasonic ultrasonic1(trigPin1, echoPin1); // Create an instance of the Ultrasonic class for sensor 1
  57. Ultrasonic ultrasonic2(trigPin2, echoPin2); // Create an instance of the Ultrasonic class for sensor 2
  58. Ultrasonic ultrasonic3(trigPin3, echoPin3); // Create an instance of the Ultrasonic class for sensor 3
  59.  
  60. void setup(void)
  61. {
  62.   // put your setup code here, to run once:
  63.  
  64.   pinMode(trigPin1, OUTPUT);
  65.   pinMode(echoPin1, INPUT);
  66.   pinMode(trigPin2, OUTPUT);
  67.   pinMode(echoPin2, INPUT);
  68.   pinMode(trigPin3, OUTPUT);
  69.   pinMode(echoPin3, INPUT);
  70.   pinMode(irPin, INPUT);
  71. }
  72.  
  73. void loop(void)
  74. {
  75.   // put your main code here, to run repeatedly:
  76.  
  77.   updateOutputs(); // Refresh output data
  78. }
  79.  
  80. void updateOutputs(void)
  81. {
  82.   trigPin1_phyData = ultrasonic1.read();
  83.   trigPin2_phyData = ultrasonic2.read();
  84.   trigPin3_phyData = ultrasonic3.read();
  85.  
  86.   // Add code to control the robot's motors and infrared sensor based on the ultrasonic sensor readings
  87. }
  88.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement