From 60a76d10a1026586884c156eaed817d3aa668001 Mon Sep 17 00:00:00 2001 From: Lurkars Date: Mon, 28 Dec 2020 17:02:46 +0100 Subject: [PATCH] rpm test --- led_bikewheel.ino | 27 +++++++++++++++++++++------ 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/led_bikewheel.ino b/led_bikewheel.ino index a81cca6..68c962c 100644 --- a/led_bikewheel.ino +++ b/led_bikewheel.ino @@ -1,16 +1,31 @@ const int HALL_PIN = 2; +const int ROUND_COUNT = 2; void setup() { + Serial.begin(115200); pinMode(LED_BUILTIN, OUTPUT); pinMode(HALL_PIN, INPUT); } void loop() { - int hall_value = digitalRead(HALL_PIN); - if (hall_value == HIGH) { - digitalWrite(LED_BUILTIN, LOW); - } else { - digitalWrite(LED_BUILTIN, HIGH); + float start = micros(); + int count = 0; + bool change = false; + while (count < ROUND_COUNT) { + if (digitalRead(HALL_PIN) == LOW) { + if(!change) { + change = true; + count++; + } + } else { + change = false; + } } - delay(10); //debounce? + + float end = micros(); + float passed = (end - start); + Serial.print("Diff: "); + Serial.print(passed); + Serial.println("micro seconds"); + }