From 0dcf13b2b125376e0cd4bcc35e4a39723cbe698b Mon Sep 17 00:00:00 2001 From: pxnmejity <2281039978@qq.com> Date: Thu, 26 Dec 2024 13:32:20 +0800 Subject: [PATCH] ADD file via upload --- mensuo.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 mensuo.py diff --git a/mensuo.py b/mensuo.py new file mode 100644 index 0000000..e72f6bd --- /dev/null +++ b/mensuo.py @@ -0,0 +1,50 @@ +#! /usr/bin/env python3 +# encoding=utf-8 + +import RPi.GPIO as GPIO +import time +import signal +import atexit +import MySQL as m + +def lock_insert(num): + t = time.strftime('%Y-%m-%d %H:%M:%S') + m.ms_insert(num, t, "open") + +def lock_update(num): + m.ms_update("close_state", "Y", num) + t = time.strftime('%Y-%m-%d %H:%M:%S') + m.ms_update("time_close", t, num) + +def lock_control(): + atexit.register(GPIO.cleanup) + + num = m.ms_select("max(number)")[0][0] + 1 + + servopin = 27 + GPIO.setmode(GPIO.BCM) + GPIO.setup(servopin, GPIO.OUT, initial=False) + p = GPIO.PWM(servopin, 50) # 50HZ:频率就是周期脉冲的周期的倒数 + p.start(0) # start(initdutycycle):占空比0-100间,0表示暂不输出 + time.sleep(2) + + + for i in range(0, 181, 10): + p.ChangeDutyCycle(2.5 + 10 * i / 180) # 设置转动角度 + time.sleep(0.02) # 等该20ms周期结束 + p.ChangeDutyCycle(0) # 归零信号 + time.sleep(0.2) + + lock_insert(str(num)) + + time.sleep(5) + + for i in range(181, 0, -10): + p.ChangeDutyCycle(2.5 + 10 * i / 180) + time.sleep(0.02) + p.ChangeDutyCycle(0) + time.sleep(0.2) + + lock_update(str(num)) + + GPIO.cleanup(servopin)