Keyestudio ESP32 Manual page 147

Starter kit
Hide thumbs Also See for ESP32:
Table of Contents

Advertisement

delayMicroseconds(10);
digitalWrite(TrigPin, LOW);
// Read the signal from the sensor: a high level pulse
//Duration is detected from the point sending "ping" command to the time
echo signal (unit: um).
float
distance
=
pulseIn(EchoPin, HIGH)
delay(10);
return
distance;
}
void
setup() {
Serial.begin(9600);//Set the baud rate to 9600
pinMode(TrigPin,
OUTPUT);//Set Trig pin to output
pinMode(EchoPin, INPUT);
}
void
loop() {
distance
=
checkdistance();
if(distance
<
10){
tone(beeppin,
262);//Play DO
delay(1000);
}
if(distance
<
20
&&
tone(beeppin,
294);//Play Re
delay(1000);
}
if(distance
<
30
&&
tone(beeppin,
330);//Play Mi
delay(1000);
}
if(distance
<
40
&&
tone(beeppin,
349);//Play fa
delay(1000);
}
if(distance
<
50
&&
tone(beeppin,
392);//Play So
delay(1000);
}
if(distance
<
60
&&
tone(beeppin,
440);//Play La
delay(1000);
}
if(distance
<
70
&&
tone(beeppin,
494);//Play Si
delay(1000);
}
Serial.println(distance);
noTone(beeppin);//Stop
}
8.5. Arduino Project
//Set Echo pin to input
distance
>
10){
distance
>
20){
distance
>
30){
distance
>
40){
distance
>
50){
distance
>
60){
/
58.00;
//Convert into distance
ESP32 Starter Kit
(continued from previous page)
receiving␣
143

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the ESP32 and is the answer not in the manual?

Questions and answers

Related Products for Keyestudio ESP32

Table of Contents

Save PDF