Advertisement
pleasedontcode

"Distance Measurement" rev_02

Dec 19th, 2024
34
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: "Distance Measurement"
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2024-12-19 07:10:15
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* This Arduino project integrates three TFMPlus for */
  21.     /* precise distance tracking by using three Serial */
  22.     /* ports in Arduino Mega, focusing on reliable sensor */
  23.     /* connections and data accuracy. */
  24. /****** END SYSTEM REQUIREMENTS *****/
  25.  
  26. /* START CODE */
  27.  
  28. /****** DEFINITION OF LIBRARIES *****/
  29. #include <TFMPlus.h>    //https://github.com/budryerson/TFMini-Plus
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34.  
  35. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  36. TFMini tfmini1; // Instance for the first TFMPlus sensor
  37. TFMini tfmini2; // Instance for the second TFMPlus sensor
  38. TFMini tfmini3; // Instance for the third TFMPlus sensor
  39.  
  40. /****** SETUP FUNCTION *****/
  41. void setup(void)
  42. {
  43.     // Initialize the serial communication with the computer
  44.     Serial.begin(9600); // Set bit rate of serial port connecting Arduino with computer
  45.  
  46.     // Initialize the TFMPlus sensors with the specified baud rate
  47.     tfmini1.begin(115200);  
  48.     tfmini2.begin(115200);
  49.     tfmini3.begin(115200);
  50. }
  51.  
  52. void loop(void)
  53. {
  54.     // Take one TF Mini distance measurement for each sensor
  55.     uint16_t dist1 = tfmini1.getDistance();
  56.     uint16_t strength1 = tfmini1.getRecentSignalStrength();
  57.     uint16_t dist2 = tfmini2.getDistance();
  58.     uint16_t strength2 = tfmini2.getRecentSignalStrength();
  59.     uint16_t dist3 = tfmini3.getDistance();
  60.     uint16_t strength3 = tfmini3.getRecentSignalStrength();
  61.  
  62.     // Display the measurement results for each sensor
  63.     Serial.print(dist1);
  64.     Serial.print(" cm      strength: ");
  65.     Serial.println(strength1);
  66.     Serial.print(dist2);
  67.     Serial.print(" cm      strength: ");
  68.     Serial.println(strength2);
  69.     Serial.print(dist3);
  70.     Serial.print(" cm      strength: ");
  71.     Serial.println(strength3);
  72.  
  73.     // Delay before the next measurement
  74.     delay(1000);
  75. }
  76.  
  77. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement