Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #30 on: January 24, 2013, 11:48:45 am » |
I understand the kind of error but I don't know what I should write.
sensors.requestTemperatures();
float temp = sensors.getTempCByIndex(0);
Serial.println(temp,DEC); char buffer[8]; dtostrf(temp,buffer,10); <====== Float temp inside to buffer in decimal type but how change it ? ht1632_putchar(6 , 8, buffer[0]); ht1632_putchar(12 , 8, buffer[1]); // ht1632_putchar(12 , 8, buffer[2]); // ht1632_putchar(18 , 8, buffer[3]); ht1632_puttinychar(19 , 8, 'o'); ht1632_putchar(24 , 8, 'C'); delay(150);
temp is the variable where the sensor give the reading of temperature buffer is where temp goes
how convert by dtostrf float temp to buffer ?
the error is
dtostrf(double, signed char, unsigned char, char*)
what is double ? what is signed char ? what is unsigned char ? what is char* ?
many thanks
Daniel
|
|
|
|
|
Logged
|
|
|
|
|
Temple, Texas
Offline
Sr. Member
Karma: 14
Posts: 354
|
 |
« Reply #31 on: January 24, 2013, 12:19:32 pm » |
http://lmgtfy.com/?q=dtostrf&l=1This has information about what the parameters need to be. If you have trouble interpreting it, post back with what you tried and why  Cheers, John
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 311
Posts: 35478
Seattle, WA USA
|
 |
« Reply #32 on: January 24, 2013, 12:19:32 pm » |
what is double ? The value to be converted. what is signed char ? The width of the string to be produced. Why an signed char? Beats me. what is unsigned char ? The precision - the number of places after the decimal point. Why an unsigned char? Beats me. what is char* ? The buffer where the string is to be created. float someTemp = 14.5; char buffer[10]; dtostrf(someTemp, 8, 3, buffer);
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #33 on: January 24, 2013, 12:43:40 pm » |
many thanks for you help
here what I write
sensors.requestTemperatures(); //int temp = sensors.getTempCByIndex(0); float temp = sensors.getTempCByIndex(0);
Serial.println(temp,DEC); char buffer[10]; // itoa(temp,buffer,10); dtostrf(temp, 8, 3, buffer); ht1632_putchar(6 , 8, buffer[0]); ht1632_putchar(12 , 8, buffer[1]); ht1632_putchar(18 , 8, buffer[2]); ht1632_putchar(24 , 8, buffer[3]); ht1632_puttinychar(32 , 8, 'o'); ht1632_putchar(35 , 8, 'C'); delay(150);
in this way change only where the temp is writed on display
ie 22 degree is written in decimal position _ _ , 22 °C
but without comma
where is the error ? I feel to be near to solution
Many thanks Daniel
|
|
|
|
|
Logged
|
|
|
|
|
Temple, Texas
Offline
Sr. Member
Karma: 14
Posts: 354
|
 |
« Reply #34 on: January 24, 2013, 01:18:14 pm » |
I think you would do better to consider the code that Paul provided as an example and an opportunity to think about how it applies to your situation rather than something to just paste into your code and report back that it doesn't work.
You should ask yourself questions like How wide do I want the number to be? e.g. "22.51345" would be 8 wide What precision do I want it to have ? e.g. "-23.434" would be a precision of 3. and Is my buffer[] big enough to hold it? Do I have room to put it on the LCD buffer[0], buffer[1], buffer[2],... buffer[width-1]
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 31
|
 |
« Reply #35 on: January 24, 2013, 01:34:06 pm » |
jhon thank you so much now with your details I've understand the meaning of it
I've changed the code here
float temp = sensors.getTempCByIndex(0);
Serial.println(temp,DEC); char buffer[10]; // itoa(temp,buffer,10); dtostrf(temp, 5, 2, buffer); ht1632_putchar(6 , 8, buffer[0]); ht1632_putchar(12 , 8, buffer[1]); ht1632_putchar(18 , 8, buffer[2]); ht1632_putchar(24 , 8, buffer[3]); ht1632_puttinychar(32 , 8, 'o'); ht1632_putchar(37 , 8, 'C'); delay(150);
now works perfectly
many thanks
|
|
|
|
|
Logged
|
|
|
|
|
Temple, Texas
Offline
Sr. Member
Karma: 14
Posts: 354
|
 |
« Reply #36 on: January 24, 2013, 01:40:02 pm » |
Great!! Then we'll leave it at that for now 
|
|
|
|
|
Logged
|
|
|
|
|
Seattle, WA USA
Online
Brattain Member
Karma: 311
Posts: 35478
Seattle, WA USA
|
 |
« Reply #37 on: January 24, 2013, 05:24:47 pm » |
You are asking for 5 characters in the output, with two digits after the decimal point, so something like 23.45. Then, you are showing 4 characters on the LCD (23.4). Why?
|
|
|
|
|
Logged
|
|
|
|
|
|