Go Down

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


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?



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


Feb 13, 2013, 04:21 pm Last 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?!


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