如何在运行程序后采集传感器上某段时间的数据
这是连续采集传感器数据的代码,我想采集某个时间段的数据应该怎么写啊?就是判断那一时间段的数据,然后执行其他事件,不影响传感器数据的连续采集。unsigned char Re_buf,counter=0;
unsigned char sign=0;
int r=1;
float A,a,w,angle,T;
void setup() {
// initialize serial:
Serial.begin(115200);
}
void loop() {
serialEvent();
if(sign)
{//Serial.println(r);
sign=0;
if(Re_buf==0x55) //检查帧头
{
switch(Re_buf )
{
case 0x51:
a = (short(Re_buf <<8| Re_buf ))/32768.0*16;
a = (short(Re_buf <<8| Re_buf ))/32768.0*16;
a = (short(Re_buf <<8| Re_buf ))/32768.0*16;
T = (short(Re_buf <<8| Re_buf ))/340.0+36.25;
break;
case 0x52:
w = (short(Re_buf <<8| Re_buf ))/32768.0*2000;
w = (short(Re_buf <<8| Re_buf ))/32768.0*2000;
w = (short(Re_buf <<8| Re_buf ))/32768.0*2000;
T = (short(Re_buf <<8| Re_buf ))/340.0+36.25;
break;
case 0x53:
angle = (short(Re_buf <<8| Re_buf ))/32768.0*180;
angle = (short(Re_buf <<8| Re_buf ))/32768.0*180;
angle = (short(Re_buf <<8| Re_buf ))/32768.0*180;
T = (short(Re_buf <<8| Re_buf ))/340.0+36.25;
Serial.print("a:");
A=sqrt(a*a+a*a+a*a);
Serial.print(A);Serial.print(" ");
Serial.print("angle:");
Serial.print(angle);Serial.print(" ");
Serial.print(angle);Serial.print(" ");
Serial.println(angle);
break;
delay(5);
}
}
}
}
void serialEvent() {
while (Serial.available()) {
Re_buf=(unsigned char)Serial.read();
if(counter==0&&Re_buf!=0x55) return;
counter++;
if(counter==11)
{
counter=0;
sign=1;
}
}
}
你用的串口输出的六轴模块吗? antbot 发表于 2016-10-21 14:24
你用的串口输出的六轴模块吗?
是的,我是做人体跌倒报警的现在只是检测到加速度和角度
不明白你想做什么。
页:
[1]