因此,我可以从我的ADXL345板上获取读数,并通过串行监视器查看读数。我如何获取一个单一的读数,并在同一个程序中使用它来做其他事情?
如果这不能解释它,我怎么能获得一个单一的读数(X:250,Y:64,Z:120),并用它来稳定我的飞机?下面是这个程序的样子,也许这能更好地解释它
从加速度计获取数据当设备开机时继续从加速度计获取数据,将此数据与第一个(Firstdata-/+currentdata)进行比较,确定要执行的功能(向上或向下移动升降,向上或向下移动多少等)循环。
我正在研究第二部分,只需要找出如何存储第一个数据。我该如何存储它?
发布于 2015-08-07 23:06:24
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.
}
}https://stackoverflow.com/questions/31839701
复制相似问题