Raspberry Pi / 数字光强光敏传感器模块

时间:2021-01-19 18:06:06

标签: python

我正在使用带有数字光敏模块的 Raspberry Pi 使我的“哑巴”洗衣机和烘干机变得“智能”。因此,对于洗衣机传感器,我在完成时收到两条消息,而不是一条消息。这没什么大不了的,但我真的希望它只在感觉到变化时才运行脚本。我想我可能会增加我的弹跳时间?

import RPi.GPIO as GPIO 
import time 
from twilio.rest import Client
def callback(channel):  
    if GPIO.input(channel):
        #print ("Washing Machine Has Finished!")
                # Your Account SID from twilio.com/console
                account_sid = "XXXXXXXXXX"
                # Your Auth Token from twilio.com/console
                auth_token  = "XXXXX"
                client = Client(account_sid, auth_token)
                message = client.messages.create(
                to="+555555", 
                from_="55555",
                body="Washing Machine Has Finished")
                #print(message.sid)
        
    else:
        print ("Washing Machine Is Running!")
GPIO.setmode(GPIO.BCM)
channel = 4
GPIO.setup(channel, GPIO.IN)
GPIO.add_event_detect(channel, GPIO.BOTH, bouncetime=300)
GPIO.add_event_callback(channel, callback)
while True:
    time.sleep(1)

0 个答案:

没有答案
相关问题