Andrea Corrado
/
water_flow_rate
water flow sensor, k64f https://www.adafruit.com/product/828
Diff: main.cpp
- Revision:
- 0:9d07fa1b15a7
- Child:
- 1:f9f5db2931e9
diff -r 000000000000 -r 9d07fa1b15a7 main.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Jan 17 11:12:32 2019 +0000 @@ -0,0 +1,31 @@ +#include "mbed.h" + +DigitalOut myled(LED1); +InterruptIn sensor(PTB10-§); + +Serial pc(USBTX, USBRX); + +int NbTopsFan; +int Calc; + +void rpm() //This function increments on the rising edge of the hall effect sensors signal +{ + NbTopsFan++; +} + +int main() { + + while(1) { + + NbTopsFan = 0; //Set NbTops to 0 ready for calculations + myled=1; + sensor.rise(&rpm); //Enables rising edge interrupt + wait_ms(1000); //Wait 1 second and count HALL pulses + sensor.rise(NULL); //Disable interrupt + myled=0; + + Calc = (NbTopsFan * 60) / 7.5; //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour + + pc.printf ("Flow L/hour: %d\r\n",Calc); //Prints the number calculated above + } +} \ No newline at end of file