I am currently trying to create a program that does something each time a button is pushed, it seems simple but for me this has been very difficult to acomplish. I am on python 2.7 (but I can go to 3 if you need me too) and I am using a pull-up-resistor setup.
The yellow wires are the pins (22, 23, and 24). The orange is positive 3.3V going to the 10K resistors. The green is ground.
I tried this code below but it simply returns, "Pin 24 is true" continuously and the buttons do nothing.
import os, RPi.GPIO as GPIO
from time import sleep
GPIO.setmode(GPIO.BCM)
GPIO.setup(23,GPIO.IN)
GPIO.setup(24,GPIO.IN)
GPIO.setup(25,GPIO.IN)
while True:
if(GPIO.input(23) == False):
print ("Pin 23 is true")
# do stuff based on pin 25 here
elif(GPIO.input(24) == True):
print ("Pin 24 is true")
# do stuff based on pin 18 here
elif(GPIO.input(25) == False):
print ("Pin 25 is true")
# and again for pin 22
Any help is much appreciated!
Thanks, Cody
GPIO.input(24) == True
should beGPIO.input(24) == False
just like you already have for the two other inputs. – Gerben Jun 17 '14 at 19:59