From 52d54bf309749f008b8c5a2c63811abd2e753336 Mon Sep 17 00:00:00 2001 From: pxnmejity <2281039978@qq.com> Date: Thu, 26 Dec 2024 13:32:05 +0800 Subject: [PATCH] ADD file via upload --- lighting.py | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 lighting.py diff --git a/lighting.py b/lighting.py new file mode 100644 index 0000000..d34f023 --- /dev/null +++ b/lighting.py @@ -0,0 +1,90 @@ +import RPi.GPIO as GPIO # 引入GPIO模块 +import time # 引入time模块 +import jiqiren as jqr + +''' +''' +def L_hcsr_open(): + + GPIO.setmode(GPIO.BCM) # 使用BCM编号方式 + + GPIO.setup(13, GPIO.OUT) # 将GPIO13设置为输出模式 + + # 无限循环 + GPIO.output(13, GPIO.HIGH) # 将GPIO13设置为高电平,点亮LED + +def L_hcsr_close(): + GPIO.output(13, GPIO.LOW) # 将GPIO13设置为低电平,熄灭LED + + GPIO.cleanup(13) # 清理释放GPIO资源,将GPIO复位 + + + +''' +============================================================================================ +以上是关于报警灯光的设计 +============================================================================================ +''' + +def L_living_open(): + + GPIO.setmode(GPIO.BCM) # 使用BCM编号方式 + + GPIO.setup(19, GPIO.OUT) # 将GPIO19设置为输出模式 + + # 无限循环 + GPIO.output(19, GPIO.HIGH) # 将GPIO19设置为高电平,点亮LED + +def L_living_close(): + GPIO.output(19, GPIO.LOW) # 将GPIO19设置为低电平,熄灭LED + + GPIO.cleanup(19) # 清理释放GPIO资源,将GPIO复位 + +''' +============================================================================================ +以上是关于客厅灯光的设计 +============================================================================================ +''' +def L_bed_open(): + + GPIO.setmode(GPIO.BCM) # 使用BCM编号方式 + + GPIO.setup(26, GPIO.OUT) # 将GPIO26设置为输出模式 + + # 无限循环 + GPIO.output(26, GPIO.HIGH) # 将GPIO26设置为高电平,点亮LED + +def L_bed_close(): + GPIO.output(26, GPIO.LOW) # 将GPIO26设置为低电平,熄灭LED + + GPIO.cleanup(26) # 清理释放GPIO资源,将GPIO复位 +''' +============================================================================================ +以上是关于卧室灯光的设计 +============================================================================================ +''' + +def L_control_open(text): + if ("卧室" in text): + L_bed_open() + jqr.Key("已打开卧室灯光") + elif ("客厅" in text): + L_living_open() + jqr.Key("已打开客厅灯光") + elif ("全部" in text or "所有" in text): + L_bed_open() + L_living_open() + jqr.Key("已打开全部灯光") + +def L_control_close(text): + if ("卧室" in text): + L_bed_close() + jqr.Key("已关闭卧室灯光") + elif ("客厅" in text): + L_living_close() + jqr.Key("已关闭客厅灯光") + elif ("全部" in text or "所有" in text): + L_bed_close() + L_living_close() + jqr.Key("已关闭所有灯光") +