If I press B1 and then I press B1 again I need to Print("Error you double pressed button 1") and
sound the active buzzer for 3 seconds and print Print("Goto button 2").
If I press B2 and then I press B2 again I need to Print("Error you double pressed button 2") and
sound the active buzzer for 3 seconds and print Print("Goto button 1").
How can I do this? The code below I put together from the web and all it does is print when I press either button and I can hold down the buttons and it will only print 1 time with each press.
Code: Select all
import machine
import utime
B1 = machine.Pin(14, machine.Pin.IN, machine.Pin.PULL_DOWN)
B2 = machine.Pin(15, machine.Pin.IN, machine.Pin.PULL_DOWN)
buzzer = machine.Pin(12, machine.Pin.OUT)
B1_last_state = False
B1_current_state = False
B2_last_state = False
B2_current_state = False
while True:
B1_current_state = B1.value()
if B1_last_state == 0 and B1_current_state == 1:
print("You pressed button 1)
utime.sleep(0.25)
B1_last_state = B1_current_state
B2_current_state = B2.value()
if B2_last_state == 0 and B2_current_state == 1:
print("You pressed button 2")
utime.sleep(0.25)
B2_last_state = B2_current_state