rpm = 60*1000/(millis() - timeold)*rpmcount;
Can someone explain to me the math being used? And if possible, can someone show me a way to improve the code in order to switch the display from rpm's to km/h ? That would be awesome thanks a lot ! smiley-sweat
Sure, no problem .
60*1000=60000
(millis() - timeold) means the number of milliseconds since the processor started running the current program MINUS the number of milliseconds saved in the variable timeold. (we can assume from the fact that in order to yield a positive result
(since there is no such thing as negative TIME) that millis() (NOW) has a value > timeold (which we can deduce cleverly from it's name that it was the value of millis() at some time in the PAST.
Let Millis =10000
Let timeold = 5000
Let rpmcount=5000
Then:
rpm = 60*1000/(millis() - timeold)rpmcount=[60000/(10000-5000)]=60000/5000=12rpmcount=60000
Since we don't know what rpmcount represents (a wheel or whatever having a diameter of whatever), we must conclude that
there is INSUFFICIENT DATA to convert this value into anything representing a speed such as mph or km/h.
millis()
Description
Returns the number of milliseconds since the Arduino board began running the current program. This number will overflow (go back to zero), after approximately 50 days.