Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 7:3f4048c1cc81
- Parent:
- 6:898a83da0661
- Child:
- 8:542ae9ef1003
diff -r 898a83da0661 -r 3f4048c1cc81 main.cpp --- a/main.cpp Tue Jun 25 14:51:58 2019 +0000 +++ b/main.cpp Tue Jun 25 15:23:40 2019 +0000 @@ -3,7 +3,15 @@ #include "IIR_filter.h" /* Notes pmic 25.06.2019: - - + - +*/ + +/* +Serial pc(SERIAL_TX, SERIAL_RX); +HP206C barometer(D14, D15); +float altitude = 0.0f; + + */ HP206C barometer(D14, D15); // 20 Hz parametrization @@ -16,7 +24,7 @@ int k; bool doRun = false; -float Ts = 0.05f; // sample time of main loop, 20 Hz +float Ts = 1.0f; // sample time of main loop, 20 Hz IIR_filter pt1(0.2f, Ts, 1.0f); float altitudef = 0.0f; @@ -30,35 +38,57 @@ // ----------------------------------------------------------------------------- int main() { - pc.baud(2000000); // for serial comm. - LoopTimer.attach(&updateLoop, Ts); // attach loop to timer interrupt + pc.baud(115200); // for serial comm. + // LoopTimer.attach(&updateLoop, Ts); // attach loop to timer interrupt Button.fall(&pressed); // attach key pressed function Button.rise(&released); // attach key pressed function k = 0; pt1.reset(0.0f); barometer.reset(); - wait_us(100); + ///* + while(1) { + altitude = barometer(); + altitudef = pt1(altitude); + if(doRun) { + // use this section to do dynamical measurements + if(doRun && k++ < 4000) { + pc.printf("%10i %10.9e\r\n", k, altitude); + } + } + wait_us(16000); + } + //*/ } +// original +/* + pc.baud(115200); + barometer.reset(); + while(1) { + altitude = barometer(); + pc.printf("altitude %f\r\n", altitude); + wait_ms(20); // don't hammer the serial console + } +*/ + // the updateLoop starts as soon as you pressed the blue botton void updateLoop(void) { altitude = barometer(); altitudef = pt1(altitude); - // pc.printf("%10i %10.6e\r\n", k, altitude); if(doRun) { - /* + ///* // use this section to do dynamical measurements if(doRun && k++ < 4000) { pc.printf("%10i %10.9e\r\n", k, altitude); } - */ - ///* + //*/ + /* // use this section to do static measurements if(doRun && k++%25 == 0) { pc.printf("%10i %10.6e\r\n", k, altitudef); } - //*/ + */ } }