Pages: [1]   Go Down
Author Topic: Value = value * 1.8 and convert to string?  (Read 365 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 2
Posts: 201
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,  folks I am very new to arduino and I would like to see if anybody could help me on that...


Well.  I am reading the serial and sending the info to a string variable.

I am doing this because I have learned the serial is readed char by char  so I sent the values to a string variable.

This variable is comma delimited so,  using strtok  I can pick what I need.

One of the results is the speed(that comes in knots).
I need to convert this speed in km/h so it will be...

Speed = Speed * 1. 8

My question is...  How can I get the value(that is in String) , use the (*  1 . smiley-cool
and convert it again into string?

Any help will be appreciated.


Thank you guys...
« Last Edit: October 28, 2013, 07:50:13 am by cabecinhas » Logged

Czech Republic
Offline Offline
Sr. Member
****
Karma: 4
Posts: 313
Absolute Beginner, yet.
Newbie in Arduino
since May 2013
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

To convert float to a string I use this:

Code:
char buffer[16];
String  StringVariable = dtostrf(FloatVariable,5,2,buffer);

Also look for strtof and atof
« Last Edit: October 27, 2013, 03:27:38 pm by K5CZ » Logged

Arduino Uno R3, Arduino Mega 2560 R3, Ethermega (R3), and some Ethernet Shields (R3), Chronodots, TMP36 sensors, DS18B20 sensors, LCDs/TFTs, RS232C to learn and play...

Offline Offline
Full Member
***
Karma: 2
Posts: 201
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi. I Did and the result was kind of splitted.. showing wrong values...

I just wanted to convert a String Variable into a float (because my value have decimal.)
After convert into a float, I need to do(value = value * 1.smiley-cool
After that, I need to convert into a String again because I need to print it.

---- heres the code I am using:
Code:
 
#include <SoftwareSerial.h>

SoftwareSerial mySerial(6, 7); // RX, TX

void setup() 
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  Serial.println("Hi there!");
 
  String info_from_gps ="2";
 // I want to multiply the "100" value that comes as String by 1.8
 // So I want to obtain 3.6 from this value
 // I think I will have to convert this value to float because there will have decimals on result , right?
 /// Well after that I need to print the result(3.6), so I think I will need to convert the result as string, right?
 
// Could you please give me an example about how to do this?
   
}

void loop() // run over and over
{
  //
}




I need to convert the velocidade  to a String variable

Any Idea?

THank you so much
« Last Edit: October 28, 2013, 07:50:42 am by cabecinhas » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The first thing that you need to clarify is if you are talking about strings or Strings. There is a world of difference between them.

Quote
heres the code I am using:
http://snippers-r-us.com might be able to help you (though I have my doubts). Here, we expect to see ALL of your code.
Logged

Offline Offline
Full Member
***
Karma: 2
Posts: 201
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, Paul. Thank you for asnwering me!

Here's a code that explais what I need to do..

Thank you very much.

Code:
#include <SoftwareSerial.h>

SoftwareSerial mySerial(6, 7); // RX, TX

void setup()  
{
  // Open serial communications and wait for port to open:
  Serial.begin(115200);
  Serial.println("Hi there!");
  
  String info ="2";
 // I want to multiply the "2" value that comes as String by 1.8
 // So I want to obtain 3.6 from this value
 // I think I will have to convert this value to float because there will have decimals on result , right?
 /// Well after that I need to print the result(3.6), so I think I will need to convert the result as string, right?
 
// Could you please give me an example about how to do this?
  
}

void loop() // run over and over
{
  //
}
« Last Edit: October 28, 2013, 07:51:43 am by cabecinhas » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26293
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ditch the String class, use C strings and "atof"to convert the string to decimal.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Full Member
***
Karma: 2
Posts: 201
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ditch the String class, use C strings and "atof"to convert the string to decimal.

Hi. AWOL. Thank you for yuor help.

Could you give me an example for this and if possible, an example to transform the result in String again for me to be able to print it?

Thank you so much smiley
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 614
Posts: 49343
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
an example to transform the result in String again for me to be able to print it?
You shouldn't need to convert a string to a String to print it. If you do, get rid of the crippled class that insists that Strings are the only way.

As for an example of using atof(), I'm sure that google has examples.
Logged

Pages: [1]   Go Up
Jump to: