kai wang
/
mbed_health
久坐警报器
Revision 3:c3f198cd0624, committed 2016-05-22
- Comitter:
- limr
- Date:
- Sun May 22 15:17:51 2016 +0000
- Parent:
- 2:6a50d967a71a
- Commit message:
- ?????;
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 6a50d967a71a -r c3f198cd0624 main.cpp --- a/main.cpp Tue May 10 15:35:45 2016 +0000 +++ b/main.cpp Sun May 22 15:17:51 2016 +0000 @@ -1,9 +1,11 @@ #include "mbed.h" #include"time.h" +#include"math.h" -#define UPA 10000//坐时最大加速度值 - -uint16_t x_a,y_a,z_a; +#define UPA1 10000//坐时最大加速度值 +#define UPA2 10000 +#define UPA3 10000 +uint16_t x_a,y_a,z_a,all_a; bool flag = 0; SPI spi_master(P0_6,P0_5,P0_7); //mosi miso sclk @@ -75,42 +77,59 @@ z_a=Dz_H<<8|Dz_L/16; } void buzzerini(void) -{ +{ while(1){ for (int i=0;i<=11;i++) { buzzer.period(1/(2*frequency[i])); // 设置PWM周期 buzzer=0.5; // 设置占空比 wait(0.4*beat[i]); // 保持节拍周期 } + get_val(); + if(x_a>UPA3) + { + buzzer.period_us(0); + break; + } +} +} +void calsample(void) +{ uint16_t sum; + clock_t st,en; + st=clock(); + get_val(); + while((double)((en=clock())-st)/CLK_TCK>100) + { + all_a=(uint16_t)sqrt((double)(x_a+y_a+z_a)); + get_val(); + sum+=all_a; + wait(10); + } } void sit_judgement() -{ int flag=0; +{ int flag=1; clock_t start,end; start=clock(); - get_val(); - get_val(); - while(x_a<=UPA) - { get_val(); - end=clock(); - if((double)(end-start)/CLK_TCK>20)//坐了20s - { flag=1; + calsample(); + while(all_a<=UPA1)//T+的情况 + { end=clock(); + if((double)(end-start)/CLK_TCK>300)//坐了300s + { flag=0; + buzzerini(); break; } + calsample(); } - while(flag) - { buzzerini(); - get_val(); - if(x_a>UPA) - { - buzzer.period_us(0); - break;} - + while(flag)//T-的情况 + { calsample(); + if(all_a<UPA2) + { + break; + } + wait(10); } } - - - - + + int main(void) { SPI_LIS3DH_Init(); @@ -120,7 +139,7 @@ if(flag) { flag=0; - wait(10);//等站起来后读取判断周期变长 + wait(5);//等站起来后读取判断周期变长 } } } \ No newline at end of file