问题描述:

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?

网友答案:
boolean firstDataRead = true;   // indicates your first Accelerometer reading

//here you will keep your first data:
int firstDataX = 0;
int firstDataY = 0;
int firstDataZ = 0;

//here you keep your current data:
int x,y,z;

void setup() {
    // initialize your arduino and ADXL345 board
}

void loop() {

    //read your ADXL345 data to x,y,z variables
    ...

    //and if this is the first reading, keep the values:
    if (firstDataRead) {
        firstDataX = x;
        firstDataY = y;
        firstDataZ = z;

        firstDataRead = false;
    }
    else {
        //Decide what function to do (Move elevons up or down, how much up or down etc) loop.
    }
}
相关阅读:
Top