Dec-11-2024, 03:34 PM
I have a Raspberry Pi on my desk. It is wired to an LED and a button. My phone sends an SSH to the Pi when it gets a text message. The SSH runs this script to turn the LED on:
The "sleep(900)" keeps the LED on for 15 minutes. I also have a function on my phone that sends an SSH to the same Pi to run this script, effectively cancelling the LED.
What I want is to press a button connected to GPIO17 that either turns the LED off or runs the script to cancel the LED. I have tried this, but it does not work:
I have confirmed that the button is open when relaxed, closed when pressed. I have confirmed that GPIO17 does function as a button, the LED does turn on and off by other means. I just can't get the button to turn it off.
1 2 3 4 5 6 7 |
from gpiozero import LED import time from time import sleep pink = LED( 20 ) pink.on() sleep( 900 ) |
1 2 3 4 5 6 |
from gpiozero import LED import time from time import sleep pink = LED( 20 ) pink.off() |
1 2 3 4 5 6 7 8 9 |
from gpiozero import LED, Button from signal import pause led = LED( 20 ) button = Button( 17 ) button.when_pressed = led.off pause() |