How can I take one reading from my accelerometer, and use it in an equation?

So, i can take reading from my ADXL345 board and i can see the reading through the serial monitor. How can I take one SINGLE reading, and use it in the same PROGRAM for other things?

If that didnt explain it, how can i take a single reading (X:250, Y:64, Z:120), and use it to stabilize my aircraft? Here's what the program would look like, maybe this will explain it better

Take DATA from Accelerometer when device powers on CONTINUE taking data from Accelerometer, compare this to the first one (Firstdata-/+currentdata) Decide what function to do (Move elevons up or down, how much up or down etc) loop.

I'm on the second part, and only need to find out how i can store that first data. How would i store it?

my current code:

/* Include the standard wire library */
#include <Wire.h>

/* Alternate I2C address of the module */
#define I2C_Add 0x53

/* ADXL345 register addresses */
#define POWER_CTL 0x2D
#define DATA_FORMAT 0x31
#define X_Axis 0x32
#define Y_Axis 0x34
#define Z_Axis 0x36

/* Accelerometer range modes */
#define RANGE_2g 0
#define RANGE_4g 1
#define RANGE_8g 2
#define RANGE_16g 3

void setup()
{
/* Initialise the I2C bus */
Wire.begin();

/* Initialise the serial interface */
Serial.begin(9600);

/* Initialise the ADXL345 */
Init_ADXL345(RANGE_2g);
}

/* Main program /
void loop()
{
/
Continually read and output all 3 axis to the serial port */
Serial.print("X: ");
Serial.print(Read_Axis(X_Axis));

Serial.print(" Y: ");
Serial.print(Read_Axis(Y_Axis));

Serial.print(" Z: ");
Serial.println(Read_Axis(Z_Axis));
}

/* Read one of the 3 axis via the I2C interface */
int Read_Axis(byte axis)
{
int Data;

Wire.beginTransmission(I2C_Add);
Wire.write(axis);
Wire.endTransmission();

Wire.beginTransmission(I2C_Add);
Wire.requestFrom(I2C_Add, 2);

/* If data is available then read it (2 bytes) */
if(Wire.available())
{
Data = (int)Wire.read();
Data = Data | (Wire.read() << 8);
}else
{
Data = 0;
}

Wire.endTransmission();
return Data;
}

/* Initialise the ADXL345 */
void Init_ADXL345(byte range)
{
Wire.beginTransmission(I2C_Add);

/* Set the sensitivity of the module */
Wire.write(DATA_FORMAT);
Wire.write(range);
Wire.endTransmission();

/* Put the module into measurement mode to start taking measurements */
Wire.beginTransmission(I2C_Add);
Wire.write(POWER_CTL);
Wire.write(0x08);

Wire.endTransmission();
}

how can i take a single reading (X:250, Y:64, Z:120), and use it to stabilize my aircraft?

bool doneThatOnce = false;

void loop()
{
   if(!doneThatOnce)
   {
     int x = Read_Axis(X_Axis);
     int y = Read_Axis(Y_Axis);
     int z = Read_Axis(Z_Axis);

     // Use x, y, z

     doneThatOnce = true;
   }
}

However, that is patently ridiculous. Your aircraft needs continuing correction, not a one-time correction.

Now, if you read the x, y, and z values in setup() as the initial values, and read the device again and again in loop(), that would make sense.

Welcome to the Forum. Please read the posting guidelines as written in Nick Gammon's two posts at the top of this Forum, especially the use of code tags when posting source code. It makes it easier for us to help you.

This is derived from your code in your Original Post

void loop()
{
/* Continually read and output all 3 axis to the serial port */
xAxisVal = Read_Axis(X_Axis);
yAxisVal = Read_Axis(Y_Axis);
zAxisVal = Read_Axis(Z_Axis);
Serial.print("X: ");
Serial.print(xAxisVal);
Serial.print(" Y: ");
Serial.print(yAxisVal);
Serial.print(" Z: ");
Serial.println(zAxisVal);

// do stuff with these values

}

...R