# Standard
import time
from machine import Pin,PWM, SoftI2C
import dht
import ds1307

# Modular
import Tone

# Main loop control
is_running : bool = True

# Sensor Defintions
dht = dht.DHT22(Pin(22))
buzzer = PWM(Pin(15))

i2c0 = SoftI2C(scl=Pin(1), sda=Pin(0), freq=100000)
rtc = ds1307.DS1307(i2c0, 0x68)

ran_on = []

def DECIDE_YOUR_Faith( temp:int , humidity : int):
    temp_thresholds = [-40, 10, 45] 

    humidity_thresholds = [20, 70]
    
    if temp <= temp_thresholds[0]:
        temp_category = 1
    elif temp <= temp_thresholds[1]:
        temp_category = 2
    else:
        temp_category = 3
    
    if humidity <= humidity_thresholds[0]:
        humidity_category = 1
    elif humidity <= humidity_thresholds[1]:
        humidity_category = 2
    else:
        humidity_category = 3
    
    final_category = round((temp_category + humidity_category) / 2)
    
    return final_category


while is_running:

  dht.measure()

  # print(rtc.datetime)

  if rtc.datetime[3] == 6 and rtc.datetime[4] == 15 and rtc.datetime[:3] not in ran_on:
    Tone.song(DECIDE_YOUR_Faith(dht.temperature(),dht.humidity()),buzzer)
    ran_on.append(rtc.datetime[:3])

  # print(f"Temperature : {dht.temperature()}°C")

  # print(f"Humidity : {dht.humidity()}%")

  time.sleep(4)

BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT
GND5VSDASCLSQWRTCDS1307+