Archives
Trending
Support
Login
clear text
XML
Django
JavaScript
MATLAB
C
C++
C#
Python
SQL
Shell
Bash
Markdown
YAML
JSON
HTML
CSS
PHP
Java
Ruby
Go
Rust
Swift
Kotlin
Arduino
TypeScript
Perl
Autohotkey
Lua
SQF
R
Scala
Haskell
Groovy
Dart
Clojure
VB.NET
Objective-C
PowerShell
Bash
CoffeeScript
Verilog
/********* 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: "Ultrasonic Control" - Source Code compiled for: Arduino Mega - Source Code created on: 2024-01-02 02:01:05 ********* Pleasedontcode.com **********/ /****** SYSTEM REQUIREMENTS *****/ /****** SYSTEM REQUIREMENT 1 *****/ /* Measure la distance à droite et à gauche */ /****** END SYSTEM REQUIREMENTS *****/ /****** DEFINITION OF LIBRARIES *****/ #include
#include
#include
/********** FUNCTION PROTOTYPES **********/ void setup(void); void loop(void); /********** DEFINITION OF DIGITAL INPUT PINS **********/ const uint8_t Ultrasonic_HCSR04_Echo_PIN_RIGHT = 3; const uint8_t Ultrasonic_HCSR04_Echo_PIN_LEFT = 4; /********** DEFINITION OF DIGITAL OUTPUT PINS **********/ const uint8_t Ultrasonic_HCSR04_Trigger_PIN = 2; /********** DEFINITION OF PWM OUTPUT PINS **********/ const uint8_t Servo_Servomotor_PWMSignal_PIN = 5; /********** DEFINITION OF LIBRARY CLASS INSTANCES **********/ Ultrasonic ultrasonicRight(Ultrasonic_HCSR04_Echo_PIN_RIGHT); Ultrasonic ultrasonicLeft(Ultrasonic_HCSR04_Echo_PIN_LEFT); Servo servoMotor; void setup(void) { // put your setup code here, to run once: pinMode(Ultrasonic_HCSR04_Echo_PIN_RIGHT, INPUT); pinMode(Ultrasonic_HCSR04_Echo_PIN_LEFT, INPUT); pinMode(Ultrasonic_HCSR04_Trigger_PIN, OUTPUT); pinMode(Servo_Servomotor_PWMSignal_PIN, OUTPUT); servoMotor.attach(Servo_Servomotor_PWMSignal_PIN); Serial.begin(9600); } void loop(void) { // Measure the distance to the right unsigned int distanceRight = ultrasonicRight.read(); Serial.print("Distance to the right: "); Serial.print(distanceRight); Serial.println(" cm"); // Measure the distance to the left unsigned int distanceLeft = ultrasonicLeft.read(); Serial.print("Distance to the left: "); Serial.print(distanceLeft); Serial.println(" cm"); delay(1000); }
Mark as private (unlisted)
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
everlasting (like CCCP)