I was wondering if there was any way to find and use the value a variable used to equal. I need to pull up that old value and compare the difference to the current value. For example, x might start out equalling 48 as a result of some input. It then changes to 104. I want to take the current value of 104 and subtract from it the original input. I've been looking around but haven't been able to find anything related to this.
How much data are you picking up and from?
If it's not much, you just need to use other variables to store and use a counter to keep track.
If you're just comparing previous value to current value, it's just
current value
blah blah
previous value = current value
next loop
current value (new one after a read or whatever)
previous value stays what it was when you set it equal to the old current value, manipulate as you want
Ditto what intp said. Use two variables. If you call the original variable "x" (which is a terrible variable name, by the way. It gives no clue as to what "x" is used for.) then you would call the previous value of "x", "previousX". Set the value of "previousX" as described by intp. The the difference would be:
Thank you! I haven't worked with coding in a long time and I'm struggling a bit to get back into it. In answer to your question INTP, I'm picking up x and y values from an accelerometer.
If you want to keep track of a number of past values, you might also want to consider holding them in an array. Each new value could go into the 0th position and push the older values along with the last one dropping out completely.
saximus:
If you want to keep track of a number of past values, you might also want to consider holding them in an array. Each new value could go into the 0th position and push the older values along with the last one dropping out completely.
Yep.
An example of this is in my barometric graphing project: Here or Here.