from microbit import *
from mb_radio import *
from mb_file import *
from mb_pins import *
from servo_7 import *

radio.on()
radio.config(length=250, channel=12,power=6,group=1)
disp_clr()
input("Close lid and [enter] to lock")
lock()
print("Waiting for password...")

while not escape():
  hash = radio.receive()
  if hash != None:
    break
print("Hash:", hash, "\nreceived")
print("Authenticating...")
authentic_hash = read_file("password.txt")
if hash == authentic_hash:
  print("Passed!")
  unlock()
  print("Waiting for lock code")
  while not escape():
    msg = radio.receive()
    if msg =="$lock$":
        lock()
        print("All locked up!")
        break
  
else:
  print("Denied access")
