arduino ide样例代码(C语言实现代码) (https://wiki.dfrobot.com.cn/_SKU_SEN0216__%E6%B0%B4%E6%B5%81%E9%87%8F%E8%AE%A1-1_8_) ``` /*************************************************** This example reads Water flow sensor Sensor.
Created 2016-3-13 By berinie Chen <bernie.chen@dfrobot.com>
GNU Lesser General Public License. See <http://www.gnu.org/licenses/> for details. All above must be included in any redistribution ****************************************************/
/***********Notice and Trouble shooting*************** 1.Connection and Diagram can be found here http://wiki.dfrobot.com.cn/index.php?title=(SKU:SEN0216)_%E6%B0%B4%E6%B5%81%E9%87%8F%E8%AE%A1-1/8%E2%80%B3#.E6.8E.A5.E7.BA.BF.E5.9B.BE 2.This code is tested on Arduino Uno. ****************************************************/ volatile double waterFlow; void setup() { Serial.begin(9600); //baudrate waterFlow = 0; attachInterrupt(0, pulse, RISING); //DIGITAL Pin 2: Interrupt 0 } void loop() { Serial.print("waterFlow:"); Serial.print(waterFlow); Serial.println(" L"); delay(500); }
void pulse() //measure the quantity of square wave { waterFlow += 1.0 / 5880.0; } ```