Commit 36930b29 authored by gujames's avatar gujames
Browse files

fixed spacing

parent e6880be2
const int trigPin = 12;
const int echoPin = 11;
const int trigPin2 = 8;
const int echoPin2 = 9;
const int motor = 3;
const int button = 13;
const int potentiometer = A0;
long duration2;
long duration;
int distance;
int distance2;
int volume;
Int volumeScaled;
void setup() {
//US1
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an Input
//US2
pinMode(trigPin2, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin2, INPUT); // Sets the echoPin as an Input
pinMode(potentiometer, INPUT);
pinMode(button, INPUT_PULLUP);
pinMode(motor, OUTPUT);
Serial.begin(9600); // Starts the serial communication
}
void loop() {
if(digitalRead(button)== HIGH) {
// Clears the trigPin
digitalWrite(trigPin2, LOW);
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin2, HIGH);
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin2, LOW);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration2 = pulseIn(echoPin2, HIGH);
duration = pulseIn(echoPin, HIGH);
//Potentiometer
volume = analogRead(potentiometer);
volumeScaled = volume* 0.25;
// Calculating the distance
distance = duration * 0.034/2;
distance2 = duration2 * 0.034/2;
if (distance2 > 30) {
Serial.println("No output");
}111
if (distance2 < 30) {
if (distance < 75) {
Serial.println(distance);
analogWrite(motor, volumeScaled);
delay(distance * 15);
}
else{
}
}
else{
digitalWrite(motor,LOW);
}
}
if(digitalRead(button)== LOW) {
digitalWrite(motor, LOW);
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment