I got this bit of code from a bigger piece of code, to work with the PX26100DV pressure sensor that I have. But I have made a seperate sketch and still can’t seem to isolate the problem. My issue is I don’t seem to be getting accurate results for my map function.
diffreading seems to be reading fine, at zero pressure it’s at 290 as I defined it and diffVolt is equal to 1.0 as it should be too! BUT when diffreading increases with increased pressure diffVolt stays at 1.0, I only saw it increases to 2.0 at 692 and 700. But at 492 and below diffVolt stayed at 1.0 … shouldn’t it adjust to 1.001, 1.002, as diffreading increases past 209? Or am I understanding the map function wrong?
Any insight or guidance would be greatly appreciated !
If you want small and fast code, just get rid of floats here. You are dealing with physical sensors that have a resolution of maybe 1000 (milliVolts, millibar, whatever), so an int is all you need for sensor values, maybe a long is necessary for storing intermediate results. Precision will be better because integer types have MORE significant digits than floats.
Wow! All of those are great responses, I really appreciate it
Thank you robtillaart for going the extra step, I do usually write my code as you instructed but for myself when I want it to look more condensed I write it as I posted; but I should post it so it's easier to read for others! Thanks again
Very sorry to bother you again, last question, sort of a follow up on your answer. The code you gave is simple and great, thank you; but since maps don't deal with floats and they deal with long and int values, does that not mean I need to change this line as well:
Probably changing it float to int ? but this would then interfere with the code you setup for me, I could do something similar to what you did to map my diffVolt to diffreading?