from machine import Pin
from time import sleep
# Push Buttons
S1 = Pin(26, Pin.IN, Pin.PULL_UP)
S2 = Pin(27, Pin.IN, Pin.PULL_UP)
S3 = Pin(14, Pin.IN, Pin.PULL_UP)
# LEDs
greenLED = Pin(2, Pin.OUT) # Unlock
redLED = Pin(4, Pin.OUT) # Locked / Alarm
print("Escape Room System Started")
while True:
# Read button states
# Pressed = 1, Not Pressed = 0
s1 = 1 if S1.value() == 0 else 0
s2 = 1 if S2.value() == 0 else 0
s3 = 1 if S3.value() == 0 else 0
# Unlock Pattern = 001
if s3 == 0 and s2 == 0 and s1 == 1:
greenLED.on()
redLED.off()
print("UNLOCK")
# Alarm Pattern = 110
elif s3 == 1 and s2 == 1 and s1 == 0:
greenLED.off()
redLED.on()
print("ALARM")
# Locked (all other combinations)
else:
greenLED.off()
redLED.on()
print("LOCKED")
sleep(0.2)