a little help?

so first off, I’m brand new to programming so be nice lol. i frequently find myself in need of a programmer these days so I’m attempting to learn myself but its slow going… i have a project on the go that will involve 3 temp sensors and some outputs to control relays for valves,pumps etc. currently my question relates to this line of code i got from an source online.

void loop(void) {

sensors.requestTemperatures(); // minden eszköztől kérjük a hőmérséklet mérést…

for (int i=0;i<maxsensors;i++)

{

flashled();

float f = sensors.getTempCByIndex(i); // egyesével kiolvassuk a mért értéket

Serial.print("Sensor ");

Serial.print(i,DEC);

Serial.println(dtostrf(f, 6, 2, buffer));

}

}

in particular the last line “Serial.println(dtostrf(f, 6, 2, buffer));” can someone help me understand it?

See if this link helps.

http://www.hobbytronics.co.uk/arduino-float-vars

dtostrf

Google's amazing, isn't it?

Let's start with two other things

  1. Reading the how to also applies to the forum :wink: Please read it and edit you post to have

[code ]tags around the code :wink:

  1. We may not be as case sensitive as the compiler is but we also would like capitals in some places :wink:

Then next, lets decompose it.

I assume you know what Serial.println() does? So we can ommit that part. leaves us with dtostrf(). A quick Google give you: Smart | Connected | Secure | Microchip Technology. So it's a way to convert a float number to ASCII text of that number. Humans are not that great at reading just bytes so we prefer text, ASCII is a common/simple way to map byte values to characters (so even numbers like here!)

Why they do it? I have no idea because Arduino IDE has a build in function for that... Maybe the code is old and it wasn't build in at the time but

Serial.println(f, 2); //two decimal places just like dtostrf() used as third argument

does the same.

float f = sensors.getTempCByIndex(i); // egyesével kiolvassuk a mért értéket

And if you plan to convert that to Fahrenheit, would you use a variable named c to hold the value?

PaulS:

float f = sensors.getTempCByIndex(i); // egyesével kiolvassuk a mért értéket

And if you plan to convert that to Fahrenheit, would you use a variable named c to hold the value?

Don't be silly - that variable would hold the speed of light.