GPIO RISING and FALLING - Raspberry Pi Forums


hi,
i've started playing gpio , python, i've put following code

code: select all

#!/usr/bin/python import time import rpi.gpio gpio gpio.setwarnings(false) gpio.setmode(gpio.board) gpio.setup(26, gpio.out, true) gpio.setup(23, gpio.out, false) gpio.setup(24, gpio.in) alerts=0  def alert_reset(channel):     global alerts     alerts -= 1     if alerts < 1:         gpio.output(23, true)         alerts = 0  def alert(channel):     global alerts     alerts += 1     if alerts > 0:         gpio.output(23, false)         localtime = time.asctime( time.localtime(time.time()) )         print "triggered :", localtime  gpio.add_event_detect(24, gpio.rising, callback=alert, bouncetime=300) gpio.add_event_detect(24, gpio.falling, callback=alert_reset, bouncetime=300)  try:     while true:         gpio.output(26, false)         time.sleep(1)         gpio.output(26, true)         time.sleep(0.1)         gpio.output(26, false)         time.sleep(0.1)         gpio.output(26, true)         time.sleep(0.2) except keyboardinterrupt:     gpio.cleanup() gpio.cleanup() 
, receive following error
traceback (most recent call last):
file "/root/test.py", line 27, in <module>
gpio.add_event_detect(24, gpio.falling, callback=alert_reset, bouncetime=300)
addeventexception: edge detection enabled gpio channel
can't assign .rising , .falling same channel , .both should work instead, have no idea how detect inside function whether .rising or .falling.
idea have multiple sensors using same function.
ideas welcome.
thanks.

just read state of gpio. if falling state false.


raspberrypi



Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial