print("Sirenes e buzzer")
import machine
import time
from machine import PWM, Pin
from time import ticks_ms
#Declaração de Variáveis:
led1 = machine.Pin(2,machine.Pin.OUT)
led2 = machine.Pin(4,machine.Pin.OUT)
estado = True
i = 0
b = 0
tref = 0
"""
def apertoubotao(Pin):
global tref
global b
if ((time.ticks_ms()-tref) > 300):
tref= time.ticks_ms()
b+=1
print("O botão foi apertado "+str(b)+" vezes")
bot = Pin(0, Pin.IN) #declara o pino 0 como entrada
bot.irq(trigger=Pin.IRQ_RISING, handler=apertoubotao)
"""
#Sirene:
ti = 0
tone = PWM(Pin(16,Pin.OUT))
while True:
if (((time.ticks_ms()- ti) >= 500)):
tone.duty(512)
led1.value(estado)
led2.value(not estado)
estado = not estado
if(estado):
tone.freq(300)
i+=1
print("Números de Sirenes: ",i)
else:
tone.freq(300)
ti = time.ticks_ms()
elif(b%2!=0):
tone.duty(0)
led1.value(0)
led2.value(0)
# '''(b%2==0) and'''