Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Distance Communication**
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-05-21 17:46:04
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* generate code for reading values of ultrasonic */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SPI.h>
- #include <LoRa.h> //https://github.com/sandeepmistry/arduino-LoRa
- #include <Ultrasonic.h> //https://github.com/ErickSimoes/Ultrasonic
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void readUltrasonicDistance(); // New function prototype
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t piyush_SX127x_DIO0_PIN_D3 = 3;
- const uint8_t piyush_HC-SR04_Echo_PIN_D5 = 5;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t piyush_SX127x_NRESET_PIN_D2 = 2;
- const uint8_t piyush_HC-SR04_Trigger_PIN_D4 = 4;
- /***** DEFINITION OF SPI PINS *****/
- const uint8_t piyush_SX127x_SPI_PIN_MOSI_D11 = 11;
- const uint8_t piyush_SX127x_SPI_PIN_MISO_D12 = 12;
- const uint8_t piyush_SX127x_SPI_PIN_SCLK_D13 = 13;
- const uint8_t piyush_SX127x_SPI_PIN_CS_D10 = 10;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool piyush_SX127x_NRESET_PIN_D2_rawData = 0;
- bool piyush_HC-SR04_Trigger_PIN_D4_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float piyush_SX127x_NRESET_PIN_D2_phyData = 0.0;
- float piyush_HC-SR04_Trigger_PIN_D4_phyData = 0.0;
- float ultrasonicDistance = 0.0; // Variable to store ultrasonic distance
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the Ultrasonic class
- Ultrasonic ultrasonic(piyush_HC-SR04_Trigger_PIN_D4, piyush_HC-SR04_Echo_PIN_D5);
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(piyush_SX127x_DIO0_PIN_D3, INPUT);
- pinMode(piyush_HC-SR04_Echo_PIN_D5, INPUT);
- pinMode(piyush_SX127x_NRESET_PIN_D2, OUTPUT);
- pinMode(piyush_HC-SR04_Trigger_PIN_D4, OUTPUT);
- pinMode(piyush_SX127x_SPI_PIN_CS_D10, OUTPUT);
- // start the SPI library:
- SPI.begin();
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- readUltrasonicDistance(); // Read distance from ultrasonic sensor
- }
- void updateOutputs()
- {
- digitalWrite(piyush_SX127x_NRESET_PIN_D2, piyush_SX127x_NRESET_PIN_D2_rawData);
- digitalWrite(piyush_HC-SR04_Trigger_PIN_D4, piyush_HC-SR04_Trigger_PIN_D4_rawData);
- }
- void readUltrasonicDistance() {
- // Read the distance from the ultrasonic sensor
- ultrasonicDistance = ultrasonic.read(); // Get distance in cm
- // You can add code here to process or display the distance
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement