first commit
This commit is contained in:
43
identificar.py
Executable file
43
identificar.py
Executable file
@@ -0,0 +1,43 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import RPi.GPIO as GPIO
|
||||
import time
|
||||
import argparse
|
||||
|
||||
# Configuración del modo de los pines GPIO
|
||||
GPIO.setmode(GPIO.BCM) # Usamos el esquema BCM, que hace referencia al número de pin GPIO
|
||||
GPIO.setup(17, GPIO.OUT) # Configuramos el pin GPIO 14 como salida
|
||||
|
||||
# Función para hacer parpadear el LED
|
||||
def parpadear_led(duracion_on, duracion_off, repeticiones):
|
||||
for _ in range(repeticiones):
|
||||
GPIO.output(17, GPIO.HIGH) # Encender el LED
|
||||
time.sleep(duracion_on) # Mantener encendido
|
||||
GPIO.output(17, GPIO.LOW) # Apagar el LED
|
||||
time.sleep(duracion_off) # Mantener apagado
|
||||
# Mantener el LED encendido al final del ciclo
|
||||
GPIO.output(17, GPIO.HIGH)
|
||||
|
||||
# Definir los argumentos de línea de comandos
|
||||
def parse_arguments():
|
||||
parser = argparse.ArgumentParser(description="Hacer parpadear un LED en GPIO 14 de la Raspberry Pi.")
|
||||
parser.add_argument('--on', type=float, default=0.5, help='Tiempo (en segundos) que el LED permanece encendido. (Default: 0.5)')
|
||||
parser.add_argument('--off', type=float, default=0.5, help='Tiempo (en segundos) que el LED permanece apagado. (Default: 0.5)')
|
||||
parser.add_argument('--reps', type=int, default=100, help='Número de veces que el LED parpadeará. (Default: 10)')
|
||||
return parser.parse_args()
|
||||
|
||||
# Ejecución del script
|
||||
if __name__ == "__main__":
|
||||
# Parsear los argumentos desde la línea de comandos
|
||||
args = parse_arguments()
|
||||
|
||||
try:
|
||||
# Llamar a la función con los argumentos pasados desde la línea de comandos
|
||||
parpadear_led(args.on, args.off, args.reps)
|
||||
except KeyboardInterrupt:
|
||||
print("Saliendo del programa...")
|
||||
GPIO.output(17, GPIO.HIGH)
|
||||
finally:
|
||||
GPIO.output(17, GPIO.HIGH) # Restablecer la configuración de los pines GPIO al finalizar el script
|
||||
|
||||
Reference in New Issue
Block a user