Skip to content

Instantly share code, notes, and snippets.

@2624789
Created November 22, 2015 04:35
Show Gist options
  • Save 2624789/7d8fd90aca259cc67f6d to your computer and use it in GitHub Desktop.
Save 2624789/7d8fd90aca259cc67f6d to your computer and use it in GitHub Desktop.
Enciende un led cuando se presiona un botón
import RPi.GPIO as GPIO
import time
# Establecemos el modo de referenciar los puertos
# Broadcom SOC channel
GPIO.setmode(GPIO.BCM)
# Desactivamos los mensajes de advertencias
GPIO.setwarnings(False)
# Configuramos el puerto para el led
# como salida
led = 18
GPIO.setup(led, GPIO.OUT)
# Configuramos el puerto para el botón
# como entrada que utiliza resistencia pull-up
boton = 23
GPIO.setup(boton, GPIO.IN, pull_up_down=GPIO.PUD_UP)
while True:
# Leemos el estado del botón
estado_boton = GPIO.input(boton)
if estado_boton == False:
# Si está presionado encendemos el led
print('botón presionado')
time.sleep(0.2)
GPIO.output(led, GPIO.HIGH)
print('led encendido')
else:
# si no lo está apagamos el led
GPIO.output(led, GPIO.LOW)
print('led apagado')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment