[Tutor] counting function calls
marcus lütolf
marcus.luetolf at bluewin.ch
Mon Apr 10 03:55:50 EDT 2017
Dear experts,
I have written the following code for motion detection with a PIR sensor
with a function and
I need to count how many times the funtion is called, but I get a traceback:
#!/usr/bin/python3
import sys, time
import RPi.GPIO as gpio
gpio.setmode(gpio.BOARD)
gpio.setup(23, gpio.IN)
count = 0
def mein_callback(pin):
count += 1
print('PIR 1 aktiviert', count)
return
try:
gpio.add_event_detect(23, gpio.RISING, callback = mein_callback)
while True:
time.sleep(2)
except KeyboardInterrupt:
print('PIR deaktiviert')
PIR 1 aktiviert
Traceback (most recent call last):
File "./PIRex.py", line 9, in mein_callback
count += 1
UnboundLocalError: local variable 'count' referenced before assignment
^CPIR deaktiviert
Tanks for help, marcus.
---
Diese E-Mail wurde von Avast Antivirus-Software auf Viren geprüft.
https://www.avast.com/antivirus
More information about the Tutor
mailing list