Keyestudio ESP32 Manual page 151

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

Advertisement

float
checkdistance() {
// preserve a short low level to ensure a clear high pulse:
digitalWrite(TrigPin, LOW);
delayMicroseconds(2);
// Trigger the sensor by a high pulse of 10um or longer
digitalWrite(TrigPin, HIGH);
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;
}
LedControl lc
=
LedControl(DIN, CLK, CS, 4);
byte data_val[4][8]
{ 0x00, 0x00, 0x00, 0x01, 0x01, 0x00, 0x00,
{ 0x00, 0x00, 0x04, 0x05, 0x05, 0x04, 0x00,
{ 0x00, 0x10, 0x14, 0x15, 0x15, 0x14, 0x10,
{ 0x40, 0x50, 0x54, 0x55, 0x55, 0x54, 0x50,
};
void
setup() {
lc.shutdown(0, false);
lc.setIntensity(0, 8);
lc.clearDisplay(0);
pinMode(TrigPin, OUTPUT);
pinMode(EchoPin, INPUT);
Serial.begin(9600);
}
void
loop() {
distance
=
checkdistance();
Serial.println(distance);
if
(distance
<
15) {
temp
=
0;
else if
}
(distance
temp
=
1;
else if
}
(distance
temp
=
2;
else if
}
(distance
temp
=
3;
}
for
(int
i
=
0; i
lc.setRow(0, i, data_val[temp][i]);
}
}
8.5. Arduino Project
//Acquire distance
=
{
//MAX72XX is in power-saving mode at startup
//Set the brightness to its maximum value
//Clear display
//Set Trig pin to output
//Set Echo pin to input
<
30
&&
distance
>
<
40
&&
distance
>
>
50) {
<
8; i++) {
/
58.00;
//Convert into distance
0x00
},
0x00
},
0x00
},
0x40
},
15) {
30) {
ESP32 Starter Kit
(continued from previous page)
receiving␣
147

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