/* aufgabeL2-1.ino
 *  Handreichungen Wahlfach BPE 10 Robotik
*/ 

#define echoPin A0
#define trigPin A1

typedef unsigned char u8;

int distance;
long duration;


//before execute loop() function,
//setup() function will execute first and only execute once
void setup() {
  Serial.begin(9600);//open serial and set the baudrate

  pinMode(trigPin, OUTPUT);
  pinMode(echoPin, INPUT);
}

//Repeat execution
void loop() {
  digitalWrite(trigPin, LOW);
  delayMicroseconds(2);
  digitalWrite(trigPin, HIGH);
  delayMicroseconds(10);
  digitalWrite(trigPin, LOW);
  // Read the echoPin, returns the sound wave travel time in microseconds
  duration = pulseIn(echoPin, HIGH);
  // Calculating the distance
  distance = duration / 58; // Speed of sound wave divided by 2 (go and back)
  Serial.print("distance: ");
  Serial.println(distance);
}
