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 Measurement"
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2025-05-21 17:50:49
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* generate code for reading values of ultrasonic */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <Ultrasonic-distance-sensor-easyC-SOLDERED.h> //https://github.com/SolderedElectronics/Soldered-Ultrasonic-Sensor-easyC-Arduino-Library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void readUltrasonicSensor(); // Function to read ultrasonic sensor values
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t piyush_HC_SR04_Echo_PIN_D5 = 5;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t piyush_HC_SR04_Trigger_PIN_D4 = 4;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool piyush_HC_SR04_Trigger_PIN_D4_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float piyush_HC_SR04_Trigger_PIN_D4_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create an instance of the Ultrasonic_Sensor class
- Ultrasonic_Sensor ultrasonicSensor(piyush_HC_SR04_Echo_PIN_D5, piyush_HC_SR04_Trigger_PIN_D4);
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(piyush_HC_SR04_Echo_PIN_D5, INPUT);
- pinMode(piyush_HC_SR04_Trigger_PIN_D4, OUTPUT);
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- updateOutputs(); // Refresh output data
- readUltrasonicSensor(); // Read values from the ultrasonic sensor
- }
- void updateOutputs()
- {
- digitalWrite(piyush_HC_SR04_Trigger_PIN_D4, piyush_HC_SR04_Trigger_PIN_D4_rawData);
- }
- void readUltrasonicSensor()
- {
- // Trigger the ultrasonic sensor and read the distance
- piyush_HC_SR04_Trigger_PIN_D4_rawData = 1; // Set trigger high
- delayMicroseconds(10); // Wait for 10 microseconds
- piyush_HC_SR04_Trigger_PIN_D4_rawData = 0; // Set trigger low
- // Get the distance from the ultrasonic sensor
- uint16_t distance = ultrasonicSensor.getDistance();
- piyush_HC_SR04_Trigger_PIN_D4_phyData = distance; // Store the distance in physical data variable
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement