風速計用プログラムです。動きません……
Dependencies: mbed
Fork of mbed_fuusoku by
やっぱり動きます(InterruptInをp30に設定すると読まなくなるボードがあります……)。最新のは校正済みです。
Fusokukei.h@0:51b2d6484a7d, 2016-11-19 (annotated)
- Committer:
- tsumagari
- Date:
- Sat Nov 19 03:49:07 2016 +0000
- Revision:
- 0:51b2d6484a7d
- Child:
- 1:d802daeec8f6
???????????????????
Who changed what in which revision?
User | Revision | Line number | New 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 | 0:51b2d6484a7d | 6 | |
tsumagari | 0:51b2d6484a7d | 7 | #define AIR_K 0.14737 |
tsumagari | 0:51b2d6484a7d | 8 | #define AIR_N 1.12 |
tsumagari | 0:51b2d6484a7d | 9 | #define AIR_A 1.4314 |
tsumagari | 0:51b2d6484a7d | 10 | #define AIR_B 0.209 |
tsumagari | 0:51b2d6484a7d | 11 | #define AIR_SUM_NUM 20 |
tsumagari | 0:51b2d6484a7d | 12 | #define AIR_BUFFER 30 |
tsumagari | 0:51b2d6484a7d | 13 | |
tsumagari | 0:51b2d6484a7d | 14 | float airSpeed = 0.0; |
tsumagari | 0:51b2d6484a7d | 15 | float airSpeed_ave = 0.0; |
tsumagari | 0:51b2d6484a7d | 16 | float airSpeed_max = 0.0; |
tsumagari | 0:51b2d6484a7d | 17 | int air_counter = 0; |
tsumagari | 0:51b2d6484a7d | 18 | float air_sum[AIR_SUM_NUM] = {0.0}; |
tsumagari | 0:51b2d6484a7d | 19 | |
tsumagari | 0:51b2d6484a7d | 20 | class Fusokukei{ |
tsumagari | 0:51b2d6484a7d | 21 | protected: |
tsumagari | 0:51b2d6484a7d | 22 | |
tsumagari | 0:51b2d6484a7d | 23 | public: |
tsumagari | 0:51b2d6484a7d | 24 | float make_ave(float s[], int n){ |
tsumagari | 0:51b2d6484a7d | 25 | float p = 0; |
tsumagari | 0:51b2d6484a7d | 26 | int i; |
tsumagari | 0:51b2d6484a7d | 27 | for(i = 0; i < n; i++){ |
tsumagari | 0:51b2d6484a7d | 28 | p += s[i]; |
tsumagari | 0:51b2d6484a7d | 29 | } |
tsumagari | 0:51b2d6484a7d | 30 | if(n != 0) |
tsumagari | 0:51b2d6484a7d | 31 | return p / n; |
tsumagari | 0:51b2d6484a7d | 32 | else |
tsumagari | 0:51b2d6484a7d | 33 | return 0; |
tsumagari | 0:51b2d6484a7d | 34 | } |
tsumagari | 0:51b2d6484a7d | 35 | |
tsumagari | 0:51b2d6484a7d | 36 | void calcAirSpeed(float x){ |
tsumagari | 0:51b2d6484a7d | 37 | air_sum[air_counter % AIR_SUM_NUM] = (float)AIR_K * (float)pow((double)x, 1 / AIR_N); |
tsumagari | 0:51b2d6484a7d | 38 | if(air_counter % AIR_SUM_NUM == 0) |
tsumagari | 0:51b2d6484a7d | 39 | air_counter = 0; |
tsumagari | 0:51b2d6484a7d | 40 | airSpeed_ave = make_ave(air_sum, AIR_SUM_NUM); |
tsumagari | 0:51b2d6484a7d | 41 | //airSpeed = airSpeed_ave*AIR_A+AIR_B; |
tsumagari | 0:51b2d6484a7d | 42 | airSpeed=airSpeed_ave; |
tsumagari | 0:51b2d6484a7d | 43 | if(airSpeed > airSpeed_max) |
tsumagari | 0:51b2d6484a7d | 44 | airSpeed_max = airSpeed; |
tsumagari | 0:51b2d6484a7d | 45 | air_counter++; |
tsumagari | 0:51b2d6484a7d | 46 | } |
tsumagari | 0:51b2d6484a7d | 47 | }; |
tsumagari | 0:51b2d6484a7d | 48 | #endif |