int t_p=4;
int e_p=16;
float ss=0.034;
long durn;
float dist_cm;
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(t_p, OUTPUT); //sent data
pinMode(e_p, INPUT); //reseive
}
void loop() {
// put your main code here, to run repeatedly:
delay(10); // this speeds up the simulation
digitalWrite(t_p,LOW);
delayMicroseconds(2);
digitalWrite(t_p,HIGH);
delayMicroseconds(2);
durn=pulseIn(e_p,HIGH);
dist_cm=durn*ss/2;
Serial.println("Distanc");
Serial.print(dist_cm);
Serial.print("\n");
delay(1000);
}
//สันต์ภพ เกษมภูสกุล ม.4/1 เลขที่ 9