Skip to content

Instantly share code, notes, and snippets.

@Arwid
Created June 15, 2018 15:35
Show Gist options
  • Save Arwid/afb96a1b72035f5f076319b45653e73e to your computer and use it in GitHub Desktop.
Save Arwid/afb96a1b72035f5f076319b45653e73e to your computer and use it in GitHub Desktop.
FlowSensorTest
#!/usr/bin/python
# Originally From: https://www.raspberrypi.org/forums/viewtopic.php?t=118230
import RPi.GPIO as GPIO
import time, sys
import datetime
FLOW_SENSOR = 17
GPIO.setmode(GPIO.BCM)
GPIO.setup(FLOW_SENSOR, GPIO.IN, pull_up_down = GPIO.PUD_UP)
global count
count = 0
def countPulse(channel):
global count
count = count + 1
GPIO.add_event_detect(FLOW_SENSOR, GPIO.FALLING, callback=countPulse)
start_time = datetime.datetime.now()
while True:
try:
time = datetime.datetime.now()
if ((time-start_time).seconds > 5):
start_time = datetime.datetime.now()
print("Total Count: %d" % count)
except KeyboardInterrupt:
print('\ncaught keyboard interrupt!, bye')
GPIO.cleanup()
sys.exit()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment