Added initial PWM code
This commit is contained in:
parent
0b2b39bb88
commit
a3a73ea1e8
26
validate.py
26
validate.py
|
@ -2,6 +2,10 @@
|
|||
|
||||
import sys
|
||||
from datetime import datetime
|
||||
import time
|
||||
import RPi.GPIO as IO
|
||||
|
||||
MOTOR_PIN = 19
|
||||
|
||||
def timestamped(s):
|
||||
"""
|
||||
|
@ -9,6 +13,25 @@ def timestamped(s):
|
|||
"""
|
||||
return "[{:%Y-%m-%d %H:%M:%S}] {}".format(datetime.now(), s)
|
||||
|
||||
def setup_pwm():
|
||||
"""
|
||||
Performs initialization for pulse width modulation.
|
||||
Returns the PWM object for the motor pin.
|
||||
"""
|
||||
IO.setwarnings(False)
|
||||
IO.setmode(IO.BCM)
|
||||
IO.setup(MOTOR_PIN, IO.OUT)
|
||||
p = IO.PWM(MOTOR_PIN, 100) # Second argument is frequency, I think
|
||||
return p
|
||||
|
||||
def unlock_door(p):
|
||||
"""
|
||||
Uses PWM to turn the motor connected to the door handle.
|
||||
"""
|
||||
p.start(50)
|
||||
time.sleep(1.0)
|
||||
p.stop()
|
||||
|
||||
def read_loop():
|
||||
"""
|
||||
Simple REPL skeleton for validating scanned IDs.
|
||||
|
@ -16,6 +39,8 @@ def read_loop():
|
|||
# Open the log file in append mode
|
||||
log_file = open("./access.log", "a")
|
||||
log_file.write(timestamped("=== Door security initiated ===\n"))
|
||||
# Initialize the PWM pin
|
||||
pwm_pin = setup_pwm()
|
||||
|
||||
# Begin the loop
|
||||
while True:
|
||||
|
@ -34,6 +59,7 @@ def read_loop():
|
|||
log_file.write(s)
|
||||
# TODO: Play open tone
|
||||
# TODO: Run unlock procedure
|
||||
unlock_door(pwm_pin)
|
||||
|
||||
if __name__ == "__main__":
|
||||
read_loop()
|
||||
|
|
Loading…
Reference in New Issue