Temperature sensor values on seven segment displays.

Hi everyone.

I'd appreciate some help on what I am trying to achieve here. So:

In my circuit I have a DS18B20 temperature sensor, and 3 seven segment displays.
What I am trying to do is to pass the values of the sensor, into the displays.

As a complete beginner coder, here is what I am thinking to do:

The temperature value is a float, in the form of 29.55
I will multiply this float with 100, in order to give it the form of an integer, like 2955

Then, I need somehow to do the following:

    • Read the first digit of the 2955 value.
    • If the first number of the int is 1, then do function 1 (a function that lights the segments for the 1 digit).
    • If first number is 2, then do function 2 etc...

I will repeat the above process for the next 2 digits of the int 2955, and hopefully I will end with my 3 seven segment displays to show the temperature values.

SO, my question is:
is there a way that I can read the numbers of the int value one by one? Or I will first need to convert the int into some other data type first?

And, above all, is my thinking valid? Or completely out of space?

Any input would be appreciated, I have searched the forum and the reference page but I am not sure how to start.

Cheers!
John

To get the first digit, you just divide by 1000, because 2955/1000 = 2 in integer division.

You then subtract 2 * 1000 from the original number, to give you 955.

Divide this by 100 to get the second digit, 9

subtract 9 * 100 to give you 55.

Divide by 10 to give you the third digit

pixle:
SO, my question is:
is there a way that I can read the numbers of the int value one by one? Or I will first need to convert the int into some other data type first?

And, above all, is my thinking valid?

Your thinking is correct. Except the direction.

It is easy to process the digits one by one from the rightmost digit to the left.

void setup() {
  Serial.begin(9600);
  int temp=2955;
  int digitFromRight=0;
  while (temp>0)
  {
    digitFromRight++;
    Serial.print(digitFromRight);
    Serial.print(". digit from right is ");
    Serial.println(temp%10); // <--- this is the digit
    temp/=10;
  }
}

Thank you both for your answers. I'll get my hands dirty with code asap :grinning: