# import modules
########################################
from machine import Pin, PWM
from time import sleep
import utime
# set up pins
#############################################
red = Pin(11, Pin.OUT)
amber = Pin(12, Pin.OUT)
green = Pin(13, Pin.OUT)
buzzer = Pin(21, Pin.OUT)
button = Pin(0, Pin.IN, Pin.PULL_DOWN)
# keypad map
#############################################
matrix_keys = [ ['1', '2', '3'],
['4', '5', '6'],
['7', '8', '9'],
['*', '0', '#']]
# keypad pins to connections
#############################################
keypad_rows = [9,8,7,6]
keypad_cols = [5,4,3]
# intialises empty lists to set up pins
#############################################
col_pins = []
row_pins = []
#key stuff
################################################
secrets =[]
passcode1 = [1, 3]
passcode2 = [6, 6]
# loop to assign GPIO pins and setup input and outputs
#############################################
for x in range(0,4):
row_pins.append(Pin(keypad_rows[x], Pin.OUT))
row_pins[x].value(1)
for x in range(0,3):
col_pins.append(Pin(keypad_cols[x], Pin.IN, Pin.PULL_DOWN))
col_pins[x].value(0)
# buzzer
#############################################
# main code
#############################################
buttonState = 0
prevState = 0
latchOn = False
# when button is pressed
##if(buttonState != prevState):
#check pressed (as opposed to letting go)
#change the latch variable
######if(latchOn ==1):
###True):
###latchOn = False
##if(latchOn == False):
## latchOn = True
# use latch variable to turn LED on and off
##morse code for sum of 13
def scankeys():
for row in range(4):
for col in range(3):
row_pins[row].high()
key = None
##if(latchOn == True):
##while True:
##buttonState = button.value()
##if button.value():
## if buzzer on this off
if col_pins[col].value() == 1:
print("You have pressed:", matrix_keys[row][col])
key_press1 = matrix_keys[row][col]
key_press2 = matrix_keys[row][col]
if(key_press1 == matrix_keys[0][0]):
buzzer.value(1)
sleep(1)
buzzer.value(2)
sleep(1)
answer1 = True
##green light and buzzer noise
##if key != 1 redlight and same for alll the others thank you
if(key_press2 == matrix_keys[0][2]):
answer2 = True
##if (answer2 == True):
## print('correct')
##green light and buzzer noise
##morse code for sum of 65
## if buzzer on this on
if col_pins[col].value() == 1:
print("You have pressed:", matrix_keys[row][col])
key_press3 = matrix_keys[row][col]
key_press4 = matrix_keys[row][col]
if(key_press3 == matrix_keys[1][2]):
answer1 = True
##green light and buzzer noise
if(key_press4 == matrix_keys[1][1]):
answer2 = True
if (answer2 == True):
print('correct');
## morse code for the answer of book
##victory ligths and buzzer
utime.sleep(0.3)
row_pins[row].low()
answer= False
else:
print("its over")
while True:
scankeys()
### An initial way to start up the keypad for morse code to be able to hack section ###
### Morse code section ###
red.on()
amber.on()
green.on()
sleep(1)
red.off()
green.off()
amber.off()
sleep(1)
amber()