import random
import time
from machine import Pin # Import for pin control
# Define LED pin (replace with your actual pin number)
led_pin = 27
# Configure the pin as output
led = Pin(led_pin, Pin.OUT) # Create a Pin object and set it to output
while True:
# Generate time for on and off states (in seconds)
tiempo_encendido = random.randint(1, 5)
tiempo_apagado = random.randint(1, 5)
# Control the LED
led.value(1) # Turn on LED (equivalent to digitalWrite(HIGH))
print("LED encendida")
time.sleep(tiempo_encendido)
led.value(0) # Turn off LED (equivalent to digitalWrite(LOW))
print("LED apagada")
time.sleep(tiempo_apagado)