49 lines
No EOL
1.2 KiB
Python
49 lines
No EOL
1.2 KiB
Python
import flask
|
|
from RPi import GPIO
|
|
import time
|
|
import threading
|
|
|
|
app = flask.Flask(import_name=__name__)
|
|
|
|
motor_pin1 = 38
|
|
motor_pin2 = 40
|
|
|
|
GPIO.setmode(GPIO.BOARD)
|
|
GPIO.setup(motor_pin1, GPIO.OUT, initial=GPIO.LOW)
|
|
GPIO.setup(motor_pin2, GPIO.OUT, initial=GPIO.LOW)
|
|
|
|
def switch_off(mini_rotation_counter=30):
|
|
GPIO.output(motor_pin1, GPIO.LOW)
|
|
GPIO.output(motor_pin2, GPIO.LOW)
|
|
for _ in range(mini_rotation_counter):
|
|
GPIO.output(motor_pin2, GPIO.HIGH)
|
|
time.sleep(0.002)
|
|
GPIO.output(motor_pin2, GPIO.LOW)
|
|
time.sleep(0.2)
|
|
|
|
def switch_on(mini_rotation_counter=30):
|
|
GPIO.output(motor_pin1, GPIO.LOW)
|
|
GPIO.output(motor_pin2, GPIO.LOW)
|
|
for _ in range(mini_rotation_counter):
|
|
GPIO.output(motor_pin1, GPIO.HIGH)
|
|
time.sleep(0.002)
|
|
GPIO.output(motor_pin1, GPIO.LOW)
|
|
time.sleep(0.2)
|
|
|
|
def into_thread():
|
|
for _ in range(7):
|
|
switch_on()
|
|
switch_off()
|
|
switch_off()
|
|
|
|
@app.route("/open")
|
|
def open_command_function():
|
|
command_applier = threading.Thread(target=into_thread)
|
|
command_applier.start()
|
|
return "Pull the door ;)\n"
|
|
|
|
|
|
|
|
if __name__=="__main__":
|
|
switch_off()
|
|
app.run(host="0.0.0.0") |