0

So my intention was to be able to detect a button press so that I could later light up an LED. However when I use this code written below. It seems that whenever I test button.is_pressed it always says that the button has been pressed, even if there is no circuit on my breadboard making that physically impossible. Now I did try different pins and then this program worked, until I made a minor adjustment to my circuit on my breadboard or restarted the Raspberry Pi 4 then it resumes saying that any pin I have used as "pressed" even if it's physically impossible.

I have used BCM numbers 17, 18, and 27. They worked at first but now they no longer behave as I expect from my program, always reporting pressed. I don't want to test any more pins in case I'm actually ending up damaging these pins when I run this function.

import time
from gpiozero import LED, Button
from signal import pause

button = Button(27)

while True:
    if button.is_pressed:
        print("Button is pressed")
    else:
        button.close()
        print("Button is not pressed")
    time.sleep(0.1)
    
pause()

It's a very simple function, I am using resistors properly. Is anyone else having this problem or know what's going on?

Stephen
  • 1
  • 2

0 Answers0