Hi all I am not a programmer and I need just a little help. This is the only thermostat sketch I could find to work with the components I have. Would someone please help change this from Celsius to Fahrenheit?
It wont let me paste the whole code so I have attached the .ino
@GolamMostafa, no it does not Turns it into 79°F and 32°F. Which seem fine to me
@DKWatson, I hate to use macros what can be done better with functions with C++... But yeah, you can make the rounding better by doing
fahrenheit = ((celsius * 18) + 5) / 10 + 32;
septillion: @GolamMostafa, no it does not Turns it into 79°F and 32°F. Which seem fine to me
@DKWatson, I hate to use macros what can be done better with functions with C++... But yeah, you can make the rounding better by doing
fahrenheit = ((celsius * 18) + 5) / 10 + 32;
You are not only fine; you are super fine. The output turns out exactly 790F and 320F for 260C and 00C.
void setup()
{
Serial.begin(9600);// put your setup code here, to run once:
byte celsius = 26;
byte fahrenheit = (celsius * 9) / 5 + 32;
Serial.print(fahrenheit, DEC);
}
void loop()
{
}
When the data types in the above codes are changed to unsigned char, I am getting 78 and 32 instead of 79 and 32. byte and unsigned char are not referring to the identical data types?
//-----------------------------------------------------------------------------------------------------------------
septillion:
byte celsius = 26;
byte fahrenheit = ((celsius * 9) + 3) / 5 + 32;
Done as integer including rounding.
In reality, 3 is not a magic number; but, apparently it is so! I am going to throw it tomorrow morning among 150 pupils and hopefully there will be some one much better than I.
GolamMostafa:
You are not only fine; you are super fine. The output turns out exactly 790F and 320F for 260C and 00C.
what's this zero to exponent to get the degree symbol? I've that on my keyboard, here are a few ones I don't use and can give away for free to copy and paste
I really appreciate the fast replies. I really am not a programmer and have no idea how to change the sketch. What I would like the sketch to do is display Fahrenheit instead of Celsius.
I don't know how to do that.
Will it take a whole re-write or can it be done with what there is.
gcarlyle22:
I really appreciate the fast replies. I really am not a programmer and have no idea how to change the sketch. What I would like the sketch to do is display Fahrenheit instead of Celsius.
I don't know how to do that.
Will it take a whole re-write or can it be done with what there is.
Thanks again
As stated, septillion did the hard part in the first reply. You need to change one line of your code from:
te = dht.readTemperature();
to:
te = ((dht.readTemperature() * 9) + 3) / 5 + 32;
This DOES mean that you need to learn to modify code using the IDE.
// Read temperature as Celsius (the default)
float t = dht.readTemperature();
// Read temperature as Fahrenheit (isFahrenheit = true)
float f = dht.readTemperature(true);
Delta_G:
You overestimate these kids these days. They can't read for understanding, that would require thinking. It's just like everything else they have, if someone isn't there to hand it to them then they just won't have it.
I think hanging round here has given you a jaundiced view of youth. There are still some kids who read stuff and think things through. But by definition they're the ones we don't see here asking basic questions and failing to understand/believe the answers. They're just writing programs and making stuff work themselves. I do wish there were a few more of them though.
Again thank you. te = ((dht.readTemperature() * 9) + 3) / 5 + 32; worked perfectly.
As I said I am not a programmer and I am too old to start learning it nor do I want to.
I remember the old BBS systems where you could go and get help and people would actually help without dogging on you.
Then the internet and forums came out and in the beginning people would still help again not flaming a person for asking for help.
If I were a programmer then I might have know there was a help file in the library. Half the time when you get a file it's just the file nothing else. So why would a person look for a help file. I guess bad programming.
When you all started programming I guarantee you had to ask for help and the person you asked didn't say MAYBE IT's OVER YOUR HEAD. They helped you.
It is over my head that's why I asked. But please don't worry I will not be asking for anymore help from here.
gcarlyle22:
As I said I am not a programmer and I am too old to start learning it nor do I want to.
I'm sorry, but now you've hit a nerve. If what you say is true, then why are you here?
When I turned 60 I started teaching myself Python. Why, because it was there. I am not a programmer, but I've been doing it for almost 50 years and I still enjoy it and helping others. Nobody's dogging on you or flaming you. We are treating you with the same respect as others who enter this forum seeking advice. If you want candy-coated platitudes, this is the wrong forum. PC stands for program counter, not politically correct.