Pages: [1]   Go Down
Author Topic: Saving decimal values  (Read 272 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there, I'm trying to solve the following problem:

I'm getting raw values from IMU by means of I2C. The values are binary (obviously), but Serial.println(val, DEC) can convert it to decimal and required values can be viewed on the serial monitor.

Now the question: how can I save these decimal values seen on serial monitor as a variable?

Thanks!
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm confused.  Why would you want to store the number in 'val' in the much less efficient form of a string of characters?  Keeping numbers as numbers is usually the most efficient way to work with them.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

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

I've got a code which gives me raw values from IMU:

Serial.print(gyro_value, DEC);

The value displayed on a serial monitor is an integer, corresponding to ADC incorporated in IMU

I want to use this integer value and apply scaling factor to get degrees/sec

I can use gyro_value, but the I need make a function which converts binary and decimal, apply scaling factor, but that will put a strain on MCU

So I'm thinking, if Serial.print(val,format) does this automatically, surely there is another way?!
« Last Edit: February 13, 2013, 11:04:36 am by john_john » Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 201
Posts: 8669
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Since the computer does math in binary, in order to "apply scaling factor" you would have to convert your string of digits back to binary.  The conversion back and forth to character strings would take much longer than applying the scaling factor in binary.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Pages: [1]   Go Up
Jump to: