Advertisement
pleasedontcode

**Sensor Communication** rev_02

May 21st, 2025
150
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: **Sensor Communication**
  13.     - Source Code NOT compiled for: Arduino Uno
  14.     - Source Code created on: 2025-05-21 17:48:19
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* generate code for reading values of ultrasonic */
  21. /****** END SYSTEM REQUIREMENTS *****/
  22.  
  23. /* START CODE */
  24.  
  25. /****** DEFINITION OF LIBRARIES *****/
  26. #include <SPI.h>
  27. #include <LoRa.h>   //https://github.com/sandeepmistry/arduino-LoRa
  28. #include <Ultrasonic.h> //https://github.com/ErickSimoes/Ultrasonic
  29.  
  30. /****** FUNCTION PROTOTYPES *****/
  31. void setup(void);
  32. void loop(void);
  33. void updateOutputs();
  34. void readUltrasonic(); // Function to read values from the ultrasonic sensor
  35.  
  36. /***** DEFINITION OF DIGITAL INPUT PINS *****/
  37. const uint8_t piyush_HC-SR04_Echo_PIN_D5        = 5;
  38.  
  39. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  40. const uint8_t piyush_HC-SR04_Trigger_PIN_D4     = 4;
  41.  
  42. /***** DEFINITION OF SPI PINS *****/
  43. const uint8_t piyush_SX127x_SPI_PIN_MOSI_D11        = 11;
  44. const uint8_t piyush_SX127x_SPI_PIN_MISO_D12        = 12;
  45. const uint8_t piyush_SX127x_SPI_PIN_SCLK_D13        = 13;
  46. const uint8_t piyush_SX127x_SPI_PIN_CS_D10      = 10;
  47.  
  48. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  49. /***** used to store raw data *****/
  50. bool    piyush_HC-SR04_Trigger_PIN_D4_rawData       = 0;
  51.  
  52. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  53. /***** used to store data after characteristic curve transformation *****/
  54. float   piyush_HC-SR04_Trigger_PIN_D4_phyData       = 0.0;
  55.  
  56. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  57. // Instantiate the Ultrasonic object
  58. Ultrasonic ultrasonic(piyush_HC-SR04_Trigger_PIN_D4, piyush_HC-SR04_Echo_PIN_D5);
  59.  
  60. void setup(void)
  61. {
  62.     // put your setup code here, to run once:
  63.  
  64.     pinMode(piyush_HC-SR04_Echo_PIN_D5, INPUT);
  65.     pinMode(piyush_HC-SR04_Trigger_PIN_D4,  OUTPUT);
  66.     pinMode(piyush_SX127x_SPI_PIN_CS_D10,   OUTPUT);
  67.    
  68.     // start the SPI library:
  69.     SPI.begin();
  70. }
  71.  
  72. void loop(void)
  73. {
  74.     // put your main code here, to run repeatedly:
  75.  
  76.     updateOutputs(); // Refresh output data
  77.     readUltrasonic(); // Read values from the ultrasonic sensor
  78. }
  79.  
  80. void updateOutputs()
  81. {
  82.     digitalWrite(piyush_HC-SR04_Trigger_PIN_D4, piyush_HC-SR04_Trigger_PIN_D4_rawData);
  83. }
  84.  
  85. void readUltrasonic()
  86. {
  87.     // Read distance from the ultrasonic sensor
  88.     piyush_HC-SR04_Trigger_PIN_D4_rawData = ultrasonic.read(); // Get the distance
  89.     piyush_HC-SR04_Trigger_PIN_D4_phyData = (float)piyush_HC-SR04_Trigger_PIN_D4_rawData; // Store as physical data
  90. }
  91.  
  92. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement