Counts 2 times, up and down edge, how can I solve this?I am a miller on a historic windmill in Belgium, I am trying to make a speed counter. Pi4 8gb
[code?]
import RPi.GPIO as GPIO
import time
import datetime
SENSOR_PIN = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN) #pull_up_down=GPIO.PUD_DOWN)
vorige_status = 0
teller = 0
vorigetijd = datetime.datetime.now()
delta = 0
try:
while True:
Sensor_state = GPIO.input (4)
if not Sensor_state == vorige_status:
teller = teller + 1
delta = datetime.datetime.now() - vorigetijd
print (delta.total_seconds())
print (1/(delta.total_seconds())) #freq
print (((1/(delta.total_seconds())))*60)# toeren per minuut
print (round (((1/(delta.total_seconds())))*60))# Afronden
print (round ((((1/(delta.total_seconds())))*60))*4) #einden
print ("------------------")
vorigetijd = datetime.datetime.now()
vorige_status = Sensor_state
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()[/code]
Counts 2 times, up and down edge, how can I solve this?
[code?]
import RPi.GPIO as GPIO
import time
import datetime
SENSOR_PIN = 4
GPIO.setmode(GPIO.BCM)
GPIO.setup(4, GPIO.IN) #pull_up_down=GPIO.PUD_DOWN)
vorige_status = 0
teller = 0
vorigetijd = datetime.datetime.now()
delta = 0
try:
while True:
Sensor_state = GPIO.input (4)
if not Sensor_state == vorige_status:
teller = teller + 1
delta = datetime.datetime.now() - vorigetijd
print (delta.total_seconds())
print (1/(delta.total_seconds())) #freq
print (((1/(delta.total_seconds())))*60)# toeren per minuut
print (round (((1/(delta.total_seconds())))*60))# Afronden
print (round ((((1/(delta.total_seconds())))*60))*4) #einden
print ("------------------")
vorigetijd = datetime.datetime.now()
vorige_status = Sensor_state
time.sleep(1)
except KeyboardInterrupt:
GPIO.cleanup()[/code]
Counts 2 times, up and down edge, how can I solve this?
Statistics: Posted by Bregt — Tue Nov 19, 2024 2:42 pm — Replies 2 — Views 17