arduino-oled-auto-gauges icon indicating copy to clipboard operation
arduino-oled-auto-gauges copied to clipboard

Use arduino map function

Open matt-downs opened this issue 5 years ago • 2 comments

Refactor code to use the built in map function in place of the normaliseSensorData and mapValueToYPos functions.

Created as a pull request because this needs to be tested and my arduino is in my dashboard.

matt-downs avatar Oct 31 '18 12:10 matt-downs

@half-finished Sure!

The boostPressure variable contains the pressure as an int: boostPressure = 1234 would mean a measurement of 12.34psi

To convert 1234 to 12.34 I cast the int to a float and divide by 100.

I then use the dtostrf function to convert and round the float to a char array so that it can be easily drawn to the screen. dtostrf is a built in function which you can read about here: http://www.hobbytronics.co.uk/arduino-float-vars

matt-downs avatar Nov 19 '18 09:11 matt-downs

I ended up using the formula from the data sheet, I seemed to get a more accurate reading from it than when using the map function.

half-finished avatar Dec 31 '18 21:12 half-finished