Download esp32/level2/distance_sensor/src/main_esp.cpp from eunzee/PCEval: direct link, hf CLI and curl.
- Browser
- Download file 845 Bytes
-
https://huggingface.co/datasets/eunzee/PCEval/resolve/main/esp32/level2/distance_sensor/src/main_esp.cpp
- Command line
-
hf download hf://datasets/eunzee/PCEval/esp32/level2/distance_sensor/src/main_esp.cpp
-
curl -L -o main_esp.cpp https://huggingface.co/datasets/eunzee/PCEval/resolve/main/esp32/level2/distance_sensor/src/main_esp.cpp
845 Bytes
| /** | |
| Measure distance with Ultrasonic distance sensor. | |
| 3 APR 2025 by Blind Author | |
| */ | |
| void setup() { | |
| Serial.begin(9600); | |
| pinMode(PIN_TRIG, OUTPUT); | |
| pinMode(PIN_ECHO, INPUT); | |
| } | |
| void loop() { | |
| digitalWrite(PIN_TRIG, HIGH); | |
| delayMicroseconds(10); | |
| digitalWrite(PIN_TRIG, LOW); | |
| int duration = pulseIn(PIN_ECHO, HIGH); | |
| int centimeter = duration / 58; | |
| Serial.println("Enter a distance in cm to compare: "); | |
| delay(200); | |
| if (Serial.available() > 0) { | |
| int inputNumber = Serial.parseInt(); | |
| if (inputNumber > centimeter) { | |
| Serial.println("Measured distance is less"); | |
| } else if (inputNumber < centimeter) { | |
| Serial.println("Measured distance is greater"); | |
| } else { | |
| Serial.println("Measured distance is equal to the target"); | |
| } | |
| } | |
| } |