Re: Too little memory space because of Floats and Sprintf
2020/05/26 11:28:09
(permalink)
In many cases you can use integer and long variables and integer math for most calculations, and then only convert to float when you need to display the value in the required units. You can also adjust external components to make things easier.

For instance, if you are reading the voltage of a 12V nominal battery, you may have a 3:1 voltage divider so 0-15V becomes 0-5V for the ADC, and that would correspond to 0-1023 counts. But you could adjust the divider so that 15V gives just 1000 counts. You could take the sum of 15 samples so that you will have an integer value of 15,000, which would be the voltage in mV. If you need to display the value in volts on a four digit display, integer divide by 10, to get 1500, convert to a string, and simply add a decimal point as needed.