void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32!");
pinMode(14, INPUT);
pinMode(26, OUTPUT);
pinMode(4, OUTPUT);
}
long wdistance(){
digitalWrite(26,LOW);
digitalWrite(26,HIGH);
delay(0.00000001);
digitalWrite(26,LOW);
float t=pulseIn(14,HIGH);
return((t*0.034/2)+1);
delay(1000);
}
void loop() {
// put your main code here, to run repeatedly:
int c=wdistance();
Serial.println(String(c));
if(c>=200){
digitalWrite(4, HIGH);
}
else{
digitalWrite(4,LOW);
}
delay(1000); // this speeds up the simulation
}