Download esp32/level2/button_duration/src/main_esp.cpp from eunzee/PCEval: direct link, hf CLI and curl.
- Browser
- Download file 700 Bytes
-
https://huggingface.co/datasets/eunzee/PCEval/resolve/main/esp32/level2/button_duration/src/main_esp.cpp
- Command line
-
hf download hf://datasets/eunzee/PCEval/esp32/level2/button_duration/src/main_esp.cpp
-
curl -L -o main_esp.cpp https://huggingface.co/datasets/eunzee/PCEval/resolve/main/esp32/level2/button_duration/src/main_esp.cpp
700 Bytes
| /** | |
| Determine how long a switch is pressed | |
| 6 APR 2025 by Blind Author | |
| */ | |
| const int inPin = 4; | |
| bool prevButtonState = HIGH; | |
| unsigned long pressStartTime = 0; | |
| unsigned long pressDuration = 0; | |
| void setup() { | |
| pinMode(inPin, INPUT); | |
| Serial.begin(9600); | |
| } | |
| void loop() { | |
| bool buttonState = digitalRead(inPin); | |
| if (prevButtonState == HIGH && buttonState == LOW) { | |
| pressStartTime = millis(); | |
| } | |
| if (prevButtonState == LOW && buttonState == HIGH) { | |
| pressDuration = (millis() - pressStartTime) / 1000; | |
| Serial.print("Button pressed duration: "); | |
| Serial.print(pressDuration); | |
| Serial.println("s"); | |
| } | |
| prevButtonState = buttonState; | |
| delay(10); | |
| } | |