Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 4829

Python • Add a timer to GPIO input for RPi

$
0
0
Hi all, Ive tried this script I found online and it works great for me. However, I would like to prevent an accidental press from sending the text. can someone please help me to where it only sends the text after the GPIO is held for over 1 second? Thank you

Code:

from twilio.rest import Clientimport RPi.GPIO as GPIOimport time# Use the Broadcom SOC Pin numbers # Setup the Pin with Internal pullups enabled and PIN in reading mode. GPIO.setmode(GPIO.BCM)GPIO.setup(18, GPIO.IN, pull_up_down = GPIO.PUD_UP)# Your Account Sid and Auth Token from twilio.com/consoleaccount_sid = 'ACXXX'auth_token = 'YOURTOKEN'client = Client(account_sid, auth_token)# Our function on what to do when the button is presseddef SendMsg(channel):    print("Sending...")   message = client.messages \    .create(         body='PyLadies Rock!',         from_='+1TWILIONUMBER',         to='+1YOURNUMBER'     )   print(message.sid)# Add our function to execute when the button pressed event happens GPIO.add_event_detect(18, GPIO.FALLING, callback = SendMsg, bouncetime = 2000)# Now wait! while 1:     time.sleep(1)   

Statistics: Posted by Thirty345 — Tue Jun 25, 2024 1:07 am



Viewing all articles
Browse latest Browse all 4829

Trending Articles