I have a pressure transducer. Reads 0-16 bar. 5V supply, Outputs 10% min, 90% max so the ADC value is 100 for minimum, 920 for maximum (confirmed with testing, it's close).
I want to map the ADC value to float, to get decimal point precision.
I don't understand (or rather can't get it to work).
basic setup (whole ino is way, way too big to post trying to cut only necessary parts)
int boilerPressureRaw;
float boilerPressure;
boilerPressureRaw = analogRead(A2);
????
Serial.print(F("Boiler Pressure Is: "));
Serial.print(boilerPressure);
Serial.println(F(" bar"));
I've come a long way, for something that seems so trivial to not work. I don't even understand where the value is returned to, or what in that example at the top is an actual variable, or just a text placeholder.
I know my min/max values for in/out but not how to implement them into the example above, and as I said, where is that value even returned to?
Input Min: 100
Input Max: 920
Out Min: 0
Out Max: 16
blh64:
You add that function into your code (after your loop() function is fine) and then you call it and the return value is assigned to a variable
God I feel like such an idiot. I had no idea that a new function was being declared. Didn't know a function would have "float" in front of it. Only functions i've worked with are void. Now as I'm typing this it makes sense what void even MEANS in the first place.
I swear, it's like every time I think I have a grasp on fundamentals, I am learning something new.
Thank you, thank you. Works perfectly, and better yet I understand why it didn't work, and why it does now.
int boilerPressureRaw;
int boilerPressure;
float boilerPressureFloat;
. . .
boilerPressureRaw = analogRead(yourAnalogPin);
boilerPressure = map(boilerPressureRaw, 0, 1023, 0, 1600);
boilerPressureFloat = boilerPressure/100;
Ah! I got it! Thank you so much! Never would have thought to map the output to a base 10 value higher, then divide. I need to think outside the box, and not so literally more often.