Thanks in advance for any advice on this...
I am creating a digital rolling measuring wheel (I know I can buy these, lol)... I am using an optical encoder that gives me 200 pulses per rev and an arduino to read the pulses, and display the distance on an OLED display in meters and feet.
Everything is working, but I am wondering if there is a better approach to displaying the distances:
I am using unsigned longs to hold my pulse count as this number could easily exceed 32,768.
I created a calibration routine where I enter a pre-determined distance (say 10 meters for example) and then roll the counter over that distance. i do this a few times and store the average number of pulses. (I realize I could just hard-code this based on wheel diameter, but I don't know what size wheel I will be using, yet - or might want to make my code work on different sized devices).
I then perform mathematical calculations to divide the pulses into the calibration distance to get a "meters per pulse" figure that is later multiplied by the number of pulses traveled when the wheel is actually being used to measure.
Because I am using longs, I don't know a great way to get numbers with decimals to properly display the metric and imperial measurements on my display.
What I have done is create a "long division" function I based off what I fund on Post #7 on this page: How can I divide two longs in an accurate double? - Programming Questions - Arduino Forum
When I calculate the distance, I am concatenating the "whole number" from my calculation with a decimal point and then the "remainder digits" into a string that I then display on my OLED.
It works, but it is kind of a "hack" way of doing this and I was wondering if there was a better / more correct / simpler way of getting a decimal result from dividing longs that I can show on my display.
Thank you for any advice.