This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm whether you accept or reject these cookies being set.

A cookie will be stored in your browser regardless of choice to prevent you being asked this question again. You will be able to change your cookie settings at any time using the link in the footer.

  • 0 voto(s) - 0 Media
  • 1
  • 2
  • 3
  • 4
  • 5
Encendido/Apagado LED con pulsador Raspberry
#1
Buenas tardes,

Disculpad, tengo una consulta, estoy con un proyecto de la raspberry pi 3, y necesito mediante python que un mismo pulsador encienda un led, lo deje encendido y al volverlo a pulsar lo apague, alguien me podría echar un cable con python? Lo agradecería.

Tengo hecho el siguiente código:

import RPi.GPIO as GPIO
import time

GPIO.setmode(GPIO.BOARD)
GPIO.setup(3, GPIO.IN)
GPIO.SETUP(11, GPIO.OUT)

while True:
         if GPIO.input(3):
                 GPIO.output(11, False)
         else:
                 GPIO.output(11, True)

[Imagen: primera.png]
  Responder
#2
Buenas tardes,

nunca he programado en python pero me da la sensación que ese programa lo que hace es encender el led siempre y cuando se pulse el pulsador. Si se suelta el pulsador se apaga. Yo añadiria estados (y más condiciones).

Además necesitarás una resistencia pull-down (o pull-up) para el pulsador.

Échale un vistazo a estos enlaces que te pueden resultar útiles :

http://mecabot-ula.org/tutoriales/arduin...smo-boton/

https://www.luisllamas.es/leer-un-pulsador-con-arduino/

Saludos.
  Responder
#3
Buenos días,

Muchas gracias por la info.

Saludos.
  Responder


Posibles temas similares…
Tema Autor Respuestas Vistas Último mensaje
  CONSULTA Cómo puedo conectar varias cámaras IP a la vez por wifi a una raspberry? erjavi_zgz 1 1,182 04-02-2022, 12:55 AM
Último mensaje: pano
  Octoprint en Raspberry y MKS SGEN problema puertos Mafer 2 917 26-10-2021, 02:27 PM
Último mensaje: Mafer
  CONSULTA Opiniones Raspberry Pi Pico RP2040 grafisoft 0 798 21-02-2021, 07:32 PM
Último mensaje: grafisoft
  Problema inicio Raspberry pantalla negra en lugar de desktop Electromecánico 3 9,844 16-09-2020, 09:31 AM
Último mensaje: wolfmech
  Conexión Raspberry a Ender 3 Lione666 3 2,161 04-08-2020, 05:17 PM
Último mensaje: ramiro24