button_led.py
A push button on GPIO27 drives an LED on GPIO17: gpiozero's when_pressed/when_released callbacks avoid polling. Bounce is filtered with bounce_time=0.05 s. A good starting point for a local interface, mindful of this board's 26-pin header.
Hardware
A Raspberry Pi Model B revision 2 (BCM2835, 26-pin GPIO header, Ethernet/USB ports moved to the board edge). One push button, one LED, a 330-ohm resistor, dupont wires.
Wiring
One button leg to GPIO27 (pin 13), the other to GND; the pull-up resistor is internal (pull_up=True). LED on GPIO17.
How it works
gpiozero enables the internal pull-up; pressing ties the pin to GND and fires the callback. pause() keeps the event loop alive.
Running it
Copy the script to the board (scp or USB stick), then run it with python3 (or bash). On Raspbian, install gpiozero with sudo apt install python3-gpiozero. The full 26-pin pinout is in the official Raspberry Pi schematic.
Variants
Use btn.wait_for_press() for blocking reads; hold_time detects long presses. Check the pin on the official P1 schematic.
button_led.py
# button_led.py — allume une LED quand on appuie sur un bouton.
# Deps: sudo apt install python3-gpiozero
# Cablage : bouton entre GPIO27 et GND, pas de resistance externe (pull-up interne).
from gpiozero import LED, Button
from signal import pause
led = LED(17) # GPIO17, broche 11
btn = Button(27, pull_up=True, bounce_time=0.05) # GPIO27, broche 13
def on_press():
print("Bouton presse")
led.on()
def on_release():
led.off()
btn.when_pressed = on_press
btn.when_released = on_release
print("Appuyez sur le bouton, Ctrl+C pour sortir")
pause()