natsu tsumagari
/
mbed_fuusoku
風速計用プログラムです。動きません……
Revision 0:51b2d6484a7d, committed 2016-11-19
- Comitter:
- tsumagari
- Date:
- Sat Nov 19 03:49:07 2016 +0000
- Commit message:
- ???????????????????
Changed in this revision
diff -r 000000000000 -r 51b2d6484a7d Fusokukei.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Fusokukei.h Sat Nov 19 03:49:07 2016 +0000 @@ -0,0 +1,48 @@ +#ifndef FUSOKUKEI_H +#define FUSOKUKEI_H + +#include "mbed.h" + + +#define AIR_K 0.14737 +#define AIR_N 1.12 +#define AIR_A 1.4314 +#define AIR_B 0.209 +#define AIR_SUM_NUM 20 +#define AIR_BUFFER 30 + +float airSpeed = 0.0; +float airSpeed_ave = 0.0; +float airSpeed_max = 0.0; +int air_counter = 0; +float air_sum[AIR_SUM_NUM] = {0.0}; + +class Fusokukei{ + protected: + + public: + float make_ave(float s[], int n){ + float p = 0; + int i; + for(i = 0; i < n; i++){ + p += s[i]; + } + if(n != 0) + return p / n; + else + return 0; + } + + void calcAirSpeed(float x){ + air_sum[air_counter % AIR_SUM_NUM] = (float)AIR_K * (float)pow((double)x, 1 / AIR_N); + if(air_counter % AIR_SUM_NUM == 0) + air_counter = 0; + airSpeed_ave = make_ave(air_sum, AIR_SUM_NUM); + //airSpeed = airSpeed_ave*AIR_A+AIR_B; + airSpeed=airSpeed_ave; + if(airSpeed > airSpeed_max) + airSpeed_max = airSpeed; + air_counter++; + } +}; +#endif \ No newline at end of file
diff -r 000000000000 -r 51b2d6484a7d main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat Nov 19 03:49:07 2016 +0000 @@ -0,0 +1,55 @@ +//計器プログラム +#include "mbed.h" +#include "Fusokukei.h" + +#define AIR_LOOP_TIME 0.01 + +Serial pc(USBTX,USBRX); + +InterruptIn FusokukeiPin(p21); +Ticker FusokukeiTicker; +Fusokukei air; +volatile int air_kaitensu= 0; + +DigitalOut led(LED1); +DigitalOut led4(LED4); +int time_counter; + +void air_countUp(); +void call_calcAirSpeed(); +void init(); +void FusokukeiInit(); + +void air_countUp(){ + air_kaitensu++; +} + +void call_calcAirSpeed(){ + air.calcAirSpeed(air_kaitensu); + air_kaitensu = 0; +} + +void init(){ + FusokukeiInit(); + led4 = 0; + time_counter = 0; +} + +void FusokukeiInit(){ + FusokukeiPin.rise(air_countUp); + FusokukeiTicker.attach(&call_calcAirSpeed, AIR_LOOP_TIME); +} + +int main(){ + init(); + while(1){ + pc.printf("test %d\n\r",time_counter); + pc.printf("air_kaitensu: %d\n\r",air_kaitensu); + pc.printf("%f\n\r",airSpeed); + led4 = 1; + wait(0.2); + led4 = 0; + wait(0.2); + time_counter++; + } +} \ No newline at end of file
diff -r 000000000000 -r 51b2d6484a7d mbed.bld --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Sat Nov 19 03:49:07 2016 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/6c34061e7c34 \ No newline at end of file