from machine import Pin, I2C, PWM
from ssd1306 import SSD1306_I2C
import utime
i2c=I2C(0,sda=Pin(0), scl=Pin(1), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
pir = Pin(28, Pin.IN, Pin.PULL_DOWN)
red = Pin(16, Pin.OUT)
green = Pin(18, Pin.OUT)
blue = Pin(20, Pin.OUT)
pwm = PWM(Pin(14))
pwm.freq(50)
buzzer = PWM(Pin(15))
buzzer.freq(500)
while True:
estado = pir.value()
oled = SSD1306_I2C(128, 64, i2c)
if estado == 1:
red.value(1)
green.value(0)
blue.value(0)
pwm.duty_u16(8000)
buzzer.duty_u16(30000)
print("Alerta de Intrusos!")
oled.text("ALERTA INTRUSO!", 0, 10)
oled.text("Puerta: Abierta", 0, 35)
elif estado == 0:
red.value(0)
green.value(1)
blue.value(0)
pwm.duty_u16(2000)
buzzer.duty_u16(0)
print("Sin movimiento")
oled.text("ZONA SEGURA", 0, 10)
oled.text("Puerta: Cerrada", 0, 35)
oled.show()
utime.sleep(0.5)Loading
ssd1306
ssd1306