From f1e06c3879e54ee0170145f19013b8c1f82f33d0 Mon Sep 17 00:00:00 2001 From: anatolykopyl <33553182+anatolykopyl@users.noreply.github.com> Date: Fri, 31 May 2019 16:43:12 +0300 Subject: [PATCH] Fixed a rounding bug Now wait times less than a second function properly --- smartboard.ino | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/smartboard.ino b/smartboard.ino index 51a5f2b..6a947e9 100644 --- a/smartboard.ino +++ b/smartboard.ino @@ -18,9 +18,9 @@ int DOT = 15; int SENS = 10; -int WAIT = 1000; //Time between updates +double WAIT = 500; //Time between updates double CIRCUMF = 3.14 * 7; //Circumference of your wheel -int dist = 0; +double dist = 0; int speedKMH = 0; bool got_signal = false; @@ -182,16 +182,8 @@ void loop() { } void update_speed() { - if (rotations > 1) { - /* Dividing dist by two because reed switch was getting triggered twice each rotation. - If you choose to go with a Hall sensor you would want to get rid of that division. */ - dist = CIRCUMF * rotations / 2; - //dist = CIRCUMF * rotations; - speedKMH = dist * 3.6 / (WAIT / 1000); - } else { - speedKMH = 0; - } + dist = CIRCUMF * rotations / 2; + speedKMH = dist * 3.6 / (WAIT / 1000); - got_signal = false; rotations = 0; }