Go Down

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

john_john

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

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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

john_john

#2
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?!

johnwasser

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: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

Go Up