diff options
Diffstat (limited to 'esp/src/lm393.cpp')
| -rw-r--r-- | esp/src/lm393.cpp | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/esp/src/lm393.cpp b/esp/src/lm393.cpp new file mode 100644 index 0000000..5eb4bdf --- /dev/null +++ b/esp/src/lm393.cpp @@ -0,0 +1,26 @@ +#include <Arduino.h> +#include "lm393.h" + +#define SENSOR_PIN 32 // ou 35 se preferir + +void setupLM393() { + pinMode(SENSOR_PIN, INPUT); +} + +int lerLM393() { + static int contagem = 0; + static unsigned long lastTime = 0; + + if (digitalRead(SENSOR_PIN) == LOW) { + contagem++; + delay(10); + } + + if (millis() - lastTime >= 1000) { + int pulsos = contagem; + contagem = 0; + lastTime = millis(); + return pulsos; + } + return 0; +} |
