Andrea Corrado
/
water_flow_rate
water flow sensor, k64f https://www.adafruit.com/product/828
main.cpp@1:f9f5db2931e9, 2019-01-17 (annotated)
- Committer:
- andcor02
- Date:
- Thu Jan 17 14:08:21 2019 +0000
- Revision:
- 1:f9f5db2931e9
- Parent:
- 0:9d07fa1b15a7
fixed formatting error.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
andcor02 | 0:9d07fa1b15a7 | 1 | #include "mbed.h" |
andcor02 | 0:9d07fa1b15a7 | 2 | |
andcor02 | 0:9d07fa1b15a7 | 3 | DigitalOut myled(LED1); |
andcor02 | 1:f9f5db2931e9 | 4 | InterruptIn sensor(PTB10); |
andcor02 | 0:9d07fa1b15a7 | 5 | |
andcor02 | 0:9d07fa1b15a7 | 6 | Serial pc(USBTX, USBRX); |
andcor02 | 0:9d07fa1b15a7 | 7 | |
andcor02 | 0:9d07fa1b15a7 | 8 | int NbTopsFan; |
andcor02 | 0:9d07fa1b15a7 | 9 | int Calc; |
andcor02 | 0:9d07fa1b15a7 | 10 | |
andcor02 | 0:9d07fa1b15a7 | 11 | void rpm() //This function increments on the rising edge of the hall effect sensors signal |
andcor02 | 0:9d07fa1b15a7 | 12 | { |
andcor02 | 0:9d07fa1b15a7 | 13 | NbTopsFan++; |
andcor02 | 0:9d07fa1b15a7 | 14 | } |
andcor02 | 0:9d07fa1b15a7 | 15 | |
andcor02 | 0:9d07fa1b15a7 | 16 | int main() { |
andcor02 | 0:9d07fa1b15a7 | 17 | |
andcor02 | 0:9d07fa1b15a7 | 18 | while(1) { |
andcor02 | 0:9d07fa1b15a7 | 19 | |
andcor02 | 0:9d07fa1b15a7 | 20 | NbTopsFan = 0; //Set NbTops to 0 ready for calculations |
andcor02 | 0:9d07fa1b15a7 | 21 | myled=1; |
andcor02 | 0:9d07fa1b15a7 | 22 | sensor.rise(&rpm); //Enables rising edge interrupt |
andcor02 | 0:9d07fa1b15a7 | 23 | wait_ms(1000); //Wait 1 second and count HALL pulses |
andcor02 | 0:9d07fa1b15a7 | 24 | sensor.rise(NULL); //Disable interrupt |
andcor02 | 0:9d07fa1b15a7 | 25 | myled=0; |
andcor02 | 0:9d07fa1b15a7 | 26 | |
andcor02 | 0:9d07fa1b15a7 | 27 | Calc = (NbTopsFan * 60) / 7.5; //(Pulse frequency x 60) / 7.5Q, = flow rate in L/hour |
andcor02 | 0:9d07fa1b15a7 | 28 | |
andcor02 | 0:9d07fa1b15a7 | 29 | pc.printf ("Flow L/hour: %d\r\n",Calc); //Prints the number calculated above |
andcor02 | 0:9d07fa1b15a7 | 30 | } |
andcor02 | 0:9d07fa1b15a7 | 31 | } |