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 Trigger
- - Source Code NOT compiled for: Arduino Uno
- - Source Code created on: 2024-04-24 19:36:50
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* gives signal when the sensor senses there is */
- /* something less then 5cm apart */
- /****** END SYSTEM REQUIREMENTS *****/
- /****** DEFINITION OF LIBRARIES *****/
- #include <HCSR04.h> // Include the HCSR04 library
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs(void); // Add function prototype for updateOutputs
- /***** DEFINITION OF DIGITAL INPUT PINS *****/
- const uint8_t us_HC_SR04_Echo_PIN_D3 = 3;
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t us_HC_SR04_Trigger_PIN_D2 = 2;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- /***** used to store raw data *****/
- bool us_HC_SR04_Trigger_PIN_D2_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- /***** used to store data after characteristic curve transformation *****/
- float us_HC_SR04_Trigger_PIN_D2_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- UltraSonicDistanceSensor distanceSensor(us_HC_SR04_Trigger_PIN_D2, us_HC_SR04_Echo_PIN_D3); // Initialize the sensor object
- void setup(void)
- {
- // put your setup code here, to run once:
- pinMode(us_HC_SR04_Echo_PIN_D3, INPUT);
- pinMode(us_HC_SR04_Trigger_PIN_D2, OUTPUT);
- Serial.begin(9600); // Initialize serial connection
- }
- void loop(void)
- {
- // put your main code here, to run repeatedly:
- float distance = distanceSensor.measureDistanceCm(); // Measure distance using the sensor
- if (distance < 5) {
- updateOutputs(); // Call updateOutputs function if distance is less than 5cm
- }
- Serial.println(distance); // Print the distance
- delay(500);
- }
- void updateOutputs()
- {
- digitalWrite(us_HC_SR04_Trigger_PIN_D2, us_HC_SR04_Trigger_PIN_D2_rawData);
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement