Greetings,
I'm using SG90 Micro Servo for simulating the door lock where the door is unlocked after typing in the password.
What I'm trying to do is so the program starts with the servo rotate at 90 degrees angle so it looks like its lock, and then if the code is right it rotates at 0 degrees and after about 10 seconds it reset back to 90 degrees.
The problem is the servo seems stuck on function lock()
at the beginning and unlock()
and not continue to complete the program.
What can I do about this situation? Thank you
door-lock.py
import time
import RPi.GPIO as GPIO
from servo import *
code = 1234
try:
while True:
lock() # The rotating thingy is at 90 degree
pass_code = input("")
if pass_code == code:
print("Opening the door")
unlock() # The rotating thingy is at 0 degree
time.sleep(10)
print("Locking the door")
lock() # The rotating thingy is back at 90 degree
except KeyboardInterrupt:
servo.stop() # or lock(), Im not sure
servo.py
def unlock():
servo.ChangeDutyCycle(7) # The rotating part is at 180 degree
def lock():
servo.ChangeDutyCycle(0) # The rotating part is at 90 degree