from machine import Pin, I2C, PWM
from ssd1306 import SSD1306_I2C
from time import sleep
# OLEd
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled = SSD1306_I2C(128, 64, i2c)
# LED
led = Pin(2, Pin.OUT)
# BUZZER
buzzer = PWM(Pin(15))
buzzer.freq(1000)
# FUNCIONES
def alerta():
led.on()
buzzer.duty(512)
oled.fill(0)
oled.text("ALERTA", 40, 10)
oled.text("Posible riesgo", 10, 30)
oled.text("detectado", 25, 45)
oled.show()
print("ALERTA ACTIVADA")
def monitoreo():
led.off()
buzzer.duty(0)
oled.fill(0)
oled.text("Monitoreando", 10, 20)
oled.text("audio...", 30, 40)
oled.show()
print("Modo monitoreo")
# LOOP
while True:
alerta()
sleep(3)
monitoreo()
sleep(3)