Go Down

### Topic: Saving decimal values (Read 467 times)previous topic - next topic

#### john_john

##### Feb 13, 2013, 03:56 pm
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!

#### johnwasser

#1
##### Feb 13, 2013, 04:15 pm
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.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

#### john_john

#2
##### Feb 13, 2013, 04:21 pmLast Edit: Feb 13, 2013, 05:04 pm by john_john Reason: 1
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?!

#### johnwasser

#3
##### Feb 13, 2013, 05:28 pm
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.
Send Bitcoin tips to: 1G2qoGwMRXx8az71DVP1E81jShxtbSh5Hp

Go Up

Please enter a valid email to subscribe