esp/arduino/sketchDistanceSerial-Ultras...

21 lines
387 B
C++

#include "Ultrasonic.h"
Ultrasonic sensor(8,9); // Trig et Echo
// defines variables
int distance; // variable for the distance measurement
void setup() {
Serial.begin(9600);
pinMode (11, OUTPUT);
pinMode (12, OUTPUT);
}
void loop () {
distance = sensor.Ranging(CM);
Serial.print("Distance: ");
Serial.print(distance);
Serial.println(" cm");
delay(100); // 100 ms
}