Hi!
I tried to figure this out last 2 weeks without manage to solve it(googleling, reading this forum for hours, testing different types of libraries etc). So I registered in here.
So, I try to make 3 digit 7-segment display(via three 74hc595 multiplexer) which displays decimal number for example 36.7(temperature which is always between 10.0 to 40.9 C) . To showing integer numbers is not a problem(working fine), but I can't manage to find out how to divide decimal number to two pieces (because i assume that to light decimal point on I have to have after decimal point numbers separated from number before decimal point).
Just because English isn't my native I will explain it other way too:
Problem: 37.7 (Temp which is always between 10.0 to 40.9 C )
need to get this format:
int a = 37
int b=7
to get it to the 7-segment display which will show 37.7.
A. Why this works (work it out with paper and pen before answering.
B. How would you deal with 2 digits after the decimal point?
float temp = 37.9;
int a;
int b;
void setup() {
// put your setup code here, to run once:
a = temp; // gets the first part as going from (casting)
//float to int drops the bit after the decimal point
Serial.begin(9600);
Serial.print("before the point ");
Serial.println(a);
// get the second part
b= temp*10-a*10;
Serial.print("after the point ");
Serial.print(b);
}
void loop() {
// put your main code here, to run repeatedly:
}
you can also use dtostrf() to create a character string out of it, and simply look for the '.' so you can pick it apart and send it, since you need a character anyway.
I just replace thermometer with variable resistor to be able to change voltage quickly. I think that there is "cleaner way to do this but it seems works so it's ok to me.
Aw man... good catch. My code example tried to save the remainder to an int. You would need a float for that to work (or, as you did, multiply the result by 10 for a single digit of precision.)
Sorry about that. Glad you figured it out despite my goof-up.