import time
from machine import Pin, PWM
buzzer = Pin(28, Pin.OUT)
motor = PWM(Pin(16))
motor.freq(50)
# while True:
# motor.duty_u16(2000)
# time.sleep(0.5)
# motor.duty_u16(4750)
# time.sleep(0.5)
row_idx = [0, 1, 2, 3]
col_idx = [15, 14, 13, 12]
row_pins = []
col_pins = []
for i in range(4):
row_pins.append(Pin(row_idx[i], Pin.OUT, Pin.PULL_DOWN))
for i in range(4):
col_pins.append(Pin(col_idx[i], Pin.IN, Pin.PULL_DOWN))
# print(row_pins)
# print(col_pins)
symbol_table = [['1', '2', '3', 'A'], ['4', '5', '6', 'B'], ['7', '8', '9', 'C'], ['*', '0', '#', 'D']]
real_password="234"
input_password=""
def key_scan():
for r in range(4):
row_pins[r].high()
for c in range(4):
if col_pins[c].value()==1:
# print(symbol_table[r][c])
global input_password
input_password+=symbol_table[r][c]
print(input_password)
row_pins[r].low()
while True:
key_scan()
time.sleep(0.13)
if len(input_password)!=0 and input_password[-1]=="#":
break
if input_password[:len(input_password)-1]==real_password:
print("Success")
motor.duty_u16(2000)
time.sleep(2)
motor.duty_u16(4750)
else:
print("Failure")
while True:
buzzer.toggle()