/*
Task
- add in statements that accomplish the following:
- If the distance is less than 100cm,
a message should tell you that you are too close.
- If the distance is between 100 and 400cm another message should be displayed.
*/
int trigPin = 3; // sends out signal
int echoPin = 2; // receives signal
void setup() {
pinMode(trigPin, OUTPUT);
pinMode(echoPin, INPUT);
Serial.begin(9600);
} // end of void setup
void loop() {
// start a new measurment
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
int duration = pulseIn(echoPin, HIGH); // measuring the time it takes for the signal to return
int centimeter = duration/58;
Serial.print("Distance in cm: ");
Serial.print(centimeter); // converts to cm
Serial.println(" ");
Serial.print("Distance in inches: ");
Serial.print(duration/148); // converts to inches
Serial.println(" ");
delay(1000);
if (centimeter < 100){
Serial.print(" ");
Serial.println("TOO CLOSE, MOVE BACK");
} // end of if
if (centimeter > 100){
Serial.print(" ");
Serial.println("Maintain Distance");
} // end of if
} // end of void loop