I have tried connecting a LED with a button like this (from "Adventures in RPi"), but with the far end of the button plugged at G (instead of F).
And I ran it with the following Python program (by following instructions from the said book):
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.OUT)
GPIO.setup(24, GPIO.IN)
while True:
if GPIO.input(24):
GPIO.output(23, True)
else:
GPIO.output(23, False)
time.sleep(0.1)
But when I tried running the program it didn't work. To debugg it I changed the if code block to this:
print("button")
##GPIO.output(23, True)
And it resulted in many prints of "button"...
- How can I fix the program (or wiring?) so that the button will turn the LED on?
Thx in advance! :)