From 7ccab61c22fafb3bb9fa5470ff8cb46217111fe4 Mon Sep 17 00:00:00 2001 From: Gustavoeklund01 Date: Mon, 27 Oct 2025 20:28:29 -0300 Subject: outros códigos MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp/src/lm393.cpp | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) (limited to 'esp/src/lm393.cpp') diff --git a/esp/src/lm393.cpp b/esp/src/lm393.cpp index e69de29..5eb4bdf 100644 --- a/esp/src/lm393.cpp +++ b/esp/src/lm393.cpp @@ -0,0 +1,26 @@ +#include +#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; +} -- cgit v1.2.3