mirror of
https://github.com/anatolykopyl/longboard-speedometer.git
synced 2026-03-26 12:54:27 +00:00
Fixed a rounding bug
Now wait times less than a second function properly
This commit is contained in:
@@ -18,9 +18,9 @@ int DOT = 15;
|
|||||||
|
|
||||||
int SENS = 10;
|
int SENS = 10;
|
||||||
|
|
||||||
int WAIT = 1000; //Time between updates
|
double WAIT = 500; //Time between updates
|
||||||
double CIRCUMF = 3.14 * 7; //Circumference of your wheel
|
double CIRCUMF = 3.14 * 7; //Circumference of your wheel
|
||||||
int dist = 0;
|
double dist = 0;
|
||||||
int speedKMH = 0;
|
int speedKMH = 0;
|
||||||
|
|
||||||
bool got_signal = false;
|
bool got_signal = false;
|
||||||
@@ -182,16 +182,8 @@ void loop() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update_speed() {
|
void update_speed() {
|
||||||
if (rotations > 1) {
|
dist = CIRCUMF * rotations / 2;
|
||||||
/* Dividing dist by two because reed switch was getting triggered twice each rotation.
|
speedKMH = dist * 3.6 / (WAIT / 1000);
|
||||||
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;
|
|
||||||
}
|
|
||||||
|
|
||||||
got_signal = false;
|
|
||||||
rotations = 0;
|
rotations = 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user