Pages: [1]   Go Down
Author Topic: Newbie Question (1 of lol) (Strings/Floats)  (Read 454 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Edison Member
*
Karma: 29
Posts: 2441
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

  bmp085_read_temperature_and_pressure(&temperature,&pressure);
  pressure = pressure - 10696; //adjust for sea level

    client.print("The Temperature Is ");
      client.print(temperature,DEC);
      client.println();
      client.print("The Barometer Reading: ");
      client.print(pressure,DEC);
      client.println();


The output looks something like this. "The Temperature Is 239 The Barometer Reading: 10334"


Now my issue, it's not 239 degrees in here nor is the pressure reading 10334, infact.. it's 23.9c and the pressure is 1033.4. How exactly do i get a . into the string? (simply insert a . and send it as a string) ..


Thanks smiley

(p.s Really enjoying Arduino, just that my background is in Pascal not C and it's a little difficult to adjust)

Logged

Offline Offline
Edison Member
*
Karma: 29
Posts: 2441
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

 char c;
  int temperature;
  long pressure;

Incase you were wondering.
Logged

Ireland
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You could try to include Stdio.h into your code "#include <stdio.h>" in here is a function called sprintf and also printf (stands for print formatted) which can be used to print strings in a specified format

See here: http://www.c-for-dummies.com/lessons/float2string/
In here there's a tutorial for working with sprintf where he has a float which is pi, he divides this by 2 and can print it out as a string with the '.'

Code:
#include <stdio.h>

int main()
{
   float pi = 3.141596;
   char halfpie[80];
   pi/=2;

   sprintf(halfpie, "%f", pi);
    printf("Here is the result: %s\n", halfpie);
   return 0;
}

This returns
Quote
Here is the result: 1.570798

Here's a link for working with sprintf
http://linux.die.net/man/3/sprintf

Also here's the arduino's own page on working with printf and sprintf
http://arduino.cc/playground/Main/Printf

Finally here's a better guide on the parameters ("%s" etc..) for these two functions

http://www.cplusplus.com/reference/clibrary/cstdio/printf/ for printf
http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/ for sprintf

Hopes this helps smiley-razz
« Last Edit: March 16, 2012, 10:29:30 am by scrineym » Logged

Pages: [1]   Go Up
Jump to: