from machine import Pin, PWM, Pin, SoftI2C
from utime import sleep
import library_oled
# Define the pin connections
red_led = Pin(17, Pin.OUT) # Red LED for Standby mode
green_led = Pin(16, Pin.OUT) # Green LED for Feeding mode
buzzer = PWM (Pin(18,Pin.OUT))
motion_sensor = Pin(2, Pin.IN)
oled_pin = SoftI2C(scl=Pin(22), sda=Pin(21))
#Object_name = library_name.class_name()
display = library_oled.SSD1306_I2C(width=128 , height=64 , i2c=oled_pin ,external_vcc= False)
#main program
while True:
green_led.off()
red_led.off()
buzzer.init(freq=1 , duty=0)
motion_status = motion_sensor.value()
print("The value of PIR sensor is", motion_status)
if motion_status == True:
for m in range (5):
red_led.on()
buzzer.init(freq=500 , duty=200)
sleep(0.4)
red_led.off()
buzzer.init(freq=500 , duty=0)
sleep(0.4)
display.fill(1)
display.text("Feeding", x=36, y=28, col=0) #x where the text starts
display.text("Mode", x= 48, y=36, col=0) #y where the text display vertically
display.show()
green_led.off()
else:
red_led.off()
green_led.on()
display.fill(1)
display.text("Standby", x=36, y=28, col=0)
display.text("Mode", x=48, y=36, col=0)
display.show()
motion_status = 0
sleep(3) #system delay