from machine import Pin
import utime
PULSE_WIDTH_US = 1000 # Ancho de pulso (µs) — modificá este valor
OUTPUT_PIN = 15
pin = Pin(OUTPUT_PIN, Pin.OUT)
SEQUENCE = [1, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0]
def generate_signal(pulse_us: int, repeat: bool = True):
# Validación del ancho de pulso
if pulse_us <= 0 or pulse_us > 1000000:
print(f"[ERROR] PULSE_WIDTH_US debe estar entre 1 y 1000 µs. Valor recibido: {pulse_us}")
return
try:
while True:
for bit in SEQUENCE:
pin.value(bit) # Pone el pin en HIGH (1) o LOW (0)
utime.sleep_us(pulse_us) # Mantiene el estado el tiempo configurado
if not repeat:
pin.value(0) # Deja el pin en LOW al terminar
print("[OK] Secuencia completada.")
break
except KeyboardInterrupt:
pin.value(0) # Seguridad: baja el pin al interrumpir
print("\n[STOP] Señal detenida por el usuario.")
if __name__ == "__main__":
generate_signal(pulse_us=PULSE_WIDTH_US, repeat=True)