所以,我可以从我的ADXL345板读取数据,我可以通过串行监视器看到读数。我怎样才能读一次,并在同一个程序中用于其他事情?
如果没有解释,我怎么能读一次(X:250,Y:64,Z:120),用它来稳定我的飞机?这是程序的样子,也许这会更好地解释
设备开机时从Accelerometer获取数据 继续从Accelerometer获取数据,将其与第一个进行比较(Firstdata - / + currentdata) 决定要做什么功能(向上或向下移动升降,向上或向下移动多少等) 循环。
我在第二部分,只需要了解我如何存储第一个数据。我该如何存放?
答案 0 :(得分:1)
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.
}
}