启动回调时给出的参数数量无效

时间:2015-10-17 14:01:22

标签: python raspberry-pi gpio raspberry-pi2

刚拿到一个Raspberry Pi套件并开始修补它。 我有以下中断:

GPIO.add_event_detect(23, GPIO.FALLING, callback=partial(sensor1, LastPour1, PourCounter1) 

,方法的定义如下:

def sensor1(LastPour1, Pourcounter1):

然而,当我参加活动时,我得到了:

TypeError: sensor1() takex exactly 2 arguments (3 given)
请赐教! 这里是大部分相关代码

# GPIO 23 set up as input. It is pulled up to stop false signals
GPIO.setup(23, GPIO.IN, pull_up_down=GPIO.PUD_UP)


VOL_PER_TICK = 5
PourCounter1 = 0
PourCounter2 = 0
LastPour1 = time.time()
LastPour2 = time.time()
Vol1 = 0
Vol2 = 0
Beer1 = ""
Beer2 = ""
workfile = 'beer_data.txt'

def sensor1(LastPour1, PourCounter1):
    "sensor 1 tripped"

    if time.time() - LastPour1 < 5:
            PourCounter1 = PourCounter1 + 1
    else:
            print "NEW POUR\n"
            PourCounter1 = 1
            LastPour1 = time.time()

    GPIO.output(19, True)
    time.sleep(0.05)
    GPIO.output(19, False)



GPIO.add_event_detect(23, GPIO.FALLING, callback=partial(sensor1, LastPour1, PourCounter1))

0 个答案:

没有答案