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.
main.cpp
00001 #include "counter.h" 00002 00003 //todo: implement 2k sample buffer and store results until client connects, implement real time clock 00004 00005 Serial pc(USBTX, USBRX); 00006 counter SF800 (p29); 00007 Timer t_a, t_b; 00008 00009 int main() { 00010 00011 t_a.start(); 00012 t_b.start(); 00013 int a_init_pulses = 0; 00014 int b_init_pulses = 0; 00015 float flowrate = 0; 00016 int time_window = 10000; 00017 00018 bool a_b_flip_flop = true; // if true use window a 00019 00020 pc.printf("\n\r*************\n\rMBED restarted\n\r*************\n"); 00021 00022 while (1) { 00023 wait(0.1); 00024 00025 if (a_b_flip_flop) { 00026 flowrate = (float)(SF800.getPulses() - a_init_pulses)/(6000 * t_a.read_ms() / 60000); 00027 } else { 00028 flowrate = (float)(SF800.getPulses() - b_init_pulses)/(6000 * t_b.read_ms() / 60000); 00029 } 00030 00031 if (t_a.read_ms() > time_window) { // switch to window B 00032 00033 pc.printf("\rswitching to window B = %i pulses detected in window A\n", SF800.getPulses() - a_init_pulses); 00034 00035 t_a.reset(); 00036 a_b_flip_flop = false; 00037 a_init_pulses = SF800.getPulses(); 00038 } 00039 00040 if (t_a.read_ms() > time_window/2 && !a_b_flip_flop) { // switch to window A 00041 00042 pc.printf("\rswitching to window A = %i pulses detected in window B\n", SF800.getPulses() - b_init_pulses); 00043 00044 t_b.reset(); 00045 a_b_flip_flop = true; 00046 b_init_pulses = SF800.getPulses(); 00047 } 00048 00049 pc.printf("\rflowrate = %f l/min", flowrate); 00050 } 00051 00052 }
Generated on Mon Jul 18 2022 16:40:19 by
1.7.2