風速計用プログラムです。動きません……

Dependencies:   mbed

Fork of mbed_fuusoku by natsu tsumagari

やっぱり動きます(InterruptInをp30に設定すると読まなくなるボードがあります……)。最新のは校正済みです。

Committer:
tsumagari
Date:
Sat Nov 19 06:37:33 2016 +0000
Revision:
1:d802daeec8f6
Parent:
0:51b2d6484a7d
Child:
2:ba1abf27fe4c
??????p30?InterruptIn????????mbed??????????????7m/s??????????Fusokukei.h?AIR_K???????????????????????

Who changed what in which revision?

UserRevisionLine numberNew contents of line
tsumagari 0:51b2d6484a7d 1 #ifndef FUSOKUKEI_H
tsumagari 0:51b2d6484a7d 2 #define FUSOKUKEI_H
tsumagari 0:51b2d6484a7d 3
tsumagari 0:51b2d6484a7d 4 #include "mbed.h"
tsumagari 0:51b2d6484a7d 5
tsumagari 1:d802daeec8f6 6 #define AIR_K 4.89799 //0.14737
tsumagari 0:51b2d6484a7d 7 #define AIR_N 1.12
tsumagari 0:51b2d6484a7d 8 #define AIR_A 1.4314
tsumagari 0:51b2d6484a7d 9 #define AIR_B 0.209
tsumagari 0:51b2d6484a7d 10 #define AIR_SUM_NUM 20
tsumagari 0:51b2d6484a7d 11 #define AIR_BUFFER 30
tsumagari 0:51b2d6484a7d 12
tsumagari 0:51b2d6484a7d 13 float airSpeed = 0.0;
tsumagari 0:51b2d6484a7d 14 float airSpeed_ave = 0.0;
tsumagari 0:51b2d6484a7d 15 float airSpeed_max = 0.0;
tsumagari 0:51b2d6484a7d 16 int air_counter = 0;
tsumagari 0:51b2d6484a7d 17 float air_sum[AIR_SUM_NUM] = {0.0};
tsumagari 0:51b2d6484a7d 18
tsumagari 1:d802daeec8f6 19 double air_r=0;
tsumagari 1:d802daeec8f6 20
tsumagari 0:51b2d6484a7d 21 class Fusokukei{
tsumagari 0:51b2d6484a7d 22 protected:
tsumagari 0:51b2d6484a7d 23
tsumagari 0:51b2d6484a7d 24 public:
tsumagari 0:51b2d6484a7d 25 float make_ave(float s[], int n){
tsumagari 0:51b2d6484a7d 26 float p = 0;
tsumagari 0:51b2d6484a7d 27 int i;
tsumagari 0:51b2d6484a7d 28 for(i = 0; i < n; i++){
tsumagari 0:51b2d6484a7d 29 p += s[i];
tsumagari 0:51b2d6484a7d 30 }
tsumagari 0:51b2d6484a7d 31 if(n != 0)
tsumagari 0:51b2d6484a7d 32 return p / n;
tsumagari 0:51b2d6484a7d 33 else
tsumagari 0:51b2d6484a7d 34 return 0;
tsumagari 0:51b2d6484a7d 35 }
tsumagari 0:51b2d6484a7d 36
tsumagari 1:d802daeec8f6 37 void calcAirSpeed(double x){
tsumagari 1:d802daeec8f6 38 air_r = x/150.0;
tsumagari 1:d802daeec8f6 39 air_sum[air_counter % AIR_SUM_NUM] = (float)AIR_K * (float)pow((double)air_r, 1 / AIR_N);
tsumagari 0:51b2d6484a7d 40 if(air_counter % AIR_SUM_NUM == 0)
tsumagari 0:51b2d6484a7d 41 air_counter = 0;
tsumagari 0:51b2d6484a7d 42 airSpeed_ave = make_ave(air_sum, AIR_SUM_NUM);
tsumagari 0:51b2d6484a7d 43 //airSpeed = airSpeed_ave*AIR_A+AIR_B;
tsumagari 0:51b2d6484a7d 44 airSpeed=airSpeed_ave;
tsumagari 0:51b2d6484a7d 45 if(airSpeed > airSpeed_max)
tsumagari 0:51b2d6484a7d 46 airSpeed_max = airSpeed;
tsumagari 0:51b2d6484a7d 47 air_counter++;
tsumagari 0:51b2d6484a7d 48 }
tsumagari 0:51b2d6484a7d 49 };
tsumagari 0:51b2d6484a7d 50 #endif