# Зорина Екатерина K0709-22.3
import time
print("Hello, Pi Pico!")
from machine import I2C, Pin
from ds1307 import DS1307
from lcd_i2c import LCD
import machine
import utime
buzzer_pin = machine.Pin(0, machine.Pin.OUT)
pwm = machine.PWM(buzzer_pin)
I2C_ADDR = 0x68
i2c = I2C(1, scl=Pin(19), sda = Pin(18), freq = 400_000)
rtc = DS1307(addr=I2C_ADDR, i2c=i2c)
relay = Pin(16, Pin.OUT)
I2C_ADDR = 0x27
NUM_ROWS = 2
NUM_COLS = 16
lcd = LCD(addr=I2C_ADDR, cols=NUM_COLS, rows=NUM_ROWS, i2c=i2c)
lcd.begin()
def get_relay_state():
if relay.value() == 1:
return 'On'
else:
return 'Off'
print(rtc.datetime)
def beep(duration, volume):
pwm.freq(1000)
pwm.duty_u16(int(65535 * volume))
utime.sleep_ms(duration)
pwm.duty_u16(0)
while True:
current_time = rtc.datetime
if int(current_time[6]) in (2, 4, 5, 6, 7):
if int(current_time[3]) > 8 and int(current_time[3]) < 23:
if int(current_time[5]) <= 10:
relay.value(1)
else:
relay.value(0)
lcd.print("{} {}:{}:{}".format(get_relay_state(), current_time[3], current_time[4], current_time[5]))
if int(current_time[5]) % 15 == 0:
beep(100, 0.5)
if int(current_time[5]) == 0:
beep(300, 0.7)
time.sleep(0.5)
lcd.clear()
time.sleep(0.5)