from machine import Pin, PWM
import time
servo = PWM(Pin(0))
servo.freq(50)
buzzer = PWM(Pin(15))
buzzer.duty_u16(0)
botao = Pin(16, Pin.IN, Pin.PULL_UP)
def mover_servo(angulo):
min_duty = 1638
max_duty = 8192
duty = int(min_duty + (max_duty - min_duty) * (angulo / 180))
servo.duty_u16(duty)
def acionar_buzzer(freq, tempo):
buzzer.freq(freq)
buzzer.duty_u16(32768)
time.sleep(tempo)
buzzer.duty_u16(0)
portao_aberto = False
mover_servo(0)
print("Sistema Iniciado. Pressione o botao para abrir.")
while True:
if botao.value() == 0:
if not portao_aberto:
print("Abrindo portão...")
acionar_buzzer(1200, 0.5)
mover_servo(90)
portao_aberto = True
time.sleep(1)
time.sleep(5)
print("Fechando portão...")
acionar_buzzer(800, 0.5)
mover_servo(0)
portao_aberto = False
time.sleep(1)
time.sleep(0.1)