from machine import Pin, PWM
import time
boton = Pin(13, Pin.IN, Pin.PULL_DOWN)
leds = [Pin(25, Pin.OUT), Pin(26, Pin.OUT), Pin(27, Pin.OUT)]
servo = PWM(Pin(12), freq=50)
buzzer = PWM(Pin(14))
buzzer.deinit()
def mover_servo(a):
duty = int((a/180)*102 + 26)
servo.duty(duty)
time.sleep(0.09)
def sonar():
for f in [100, 500, 1000]:
buzzer.init(freq=f, duty=512)
time.sleep(0.1)
buzzer.deinit()
def luces():
for led in leds:
led.value(1)
time.sleep(0.1)
led.value(0)
def alarma():
for _ in range(5):
mover_servo(0)
luces()
mover_servo(90)
sonar()
mover_servo(180)
time.sleep(0.2)
while True:
if boton.value() == 1:
alarma()