You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
2.9 KiB

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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("已关闭所有灯光")