i have created python script mail.py which include code of sending mail when gpio 4 is pressed..my gpio 4 is PULLED UP switch ,but problem is that when i directly run the script it runs means it send mail but when i press that switch it doesn't run before pressing switch it goes outside the loop and script doen't run,also email doesn't send..i have also put delay for that..i think problem is when i press the switch one time it have to store the state of switch so after 10 second it read the state but i can't store the state of switch..if any suggestion plz tell me..thanks in advance..
you can write the listener inside a loop and also the mail functionality as function
like
GPIO.setup(23, GPIO.IN, pull_up_down = GPIO.PUD_DOWN)
GPIO.setup(24, GPIO.IN, pull_up_down = GPIO.PUD_UP)
while True:
if(GPIO.input(23) ==1):
# button pressed then cal the mail() function
#after excutting the function if need you can again set the pinpoint back to 0
if(GPIO.input(24) == 0):
print(“Button 2 pressed”)
GPIO.cleanup()
try the example
Raspberry pi:send email when PULLED UP switch is pressed