如何检测功能中第二次按下按钮的时间

时间:2019-04-13 16:23:28

标签: python raspberry-pi

我正在Python3的Raspberry Pi上编写代码以控制门的打开。我有一个由按下按钮触发的代码,它工作正常。稍后在代码中,当再次按下同一按钮并且不起作用时,我想采取一些其他措施。

有人可以帮我吗?

谢谢。

#/usr/bin/python3

def read_code():
    kod = ''
    klawisz = ''     
    for event in dev.read_loop():
        if event.type == ecodes.EV_KEY:
            e = categorize(event)
            if e.keystate == e.key_down:
                klawisz = e.keycode[4:]
                if klawisz != "ESC":
                    kod = (kod + klawisz)
                    print(kod)
                else:
                    break
    return kod

while True:
    button_state = GPIO.input(Button)
    if button_state == 0:
        print('TYPE CODE')
        while read_code() !='1234':
            GPIO.output(LED,GPIO.HIGH)
            print('WRONG CODE')
        else:
            print('CODE IS CORRECT')
       /// trying to detect button being pressed again but not working///
            button_state2 = GPIO.input(Button)
            if button_state2 == 0:
            print('TYPE CODE')
            while read_code() !='5678':
                GPIO.output(LED,GPIO.HIGH)
                print('WRONG CODE')
            else:
                print('CODE IS CORRECT')

    else:
        GPIO.output(LED,GPIO.LOW)

0 个答案:

没有答案