Looking for a simple input pulse counter for no more then 2000 counts per minute. Right now I have it set
if gpio.input(countswitch): data["count"] += 1
which works but I get 100 plus counts for each pulse I only want one count per pulse.
Here is a pigpio Python example. You use the same logic in any programming language.
In practice you would use GPIO callbacks on level change rather than polling.
The time.sleep(0.01) is kind to other programs which want to run.
#!/usr/bin/env python import time import pigpio GPIO=4 pi = pigpio.pi() if not pi.connected: exit() count=0 last_state = pi.read(GPIO) while True: now = pi.read(GPIO) if now != last_state: last_state = now if now == 1: count += 1 print(count) time.sleep(0.01)
So I feel, your problem here is that one "high" input from the gpio is being read as more than one pulse in your variable. I'm pretty sure that you are using a while loop, as in
data["count"] += 1
so I suggest u should try this code out
def Check_For_ONE_CLICK(): while 1: c=0 if gpio.input(coutswitch): if c==0: data["count"]+=1 c+=1 else: break
Hope it helps you...