from machine import Pin, PWM
from time import sleep
import dht
import os
CLR = "\x1b[0K"
UP = "\x1B[3A"
pwm0 = PWM(Pin(19))
dht22 = dht.DHT22(Pin(25))
def pulse(frequency, duty, duty_cycle):
pwm0.freq(frequency)
pwm0.duty(duty)
print(UP,"the temperature is {:0.2f}".format(temperature), CLR, "\n", "The frequency is {:2d} with a duty cycle of {:3d}".format(frequency, duty_cycle), CLR, "\n")
def LED(temperature):
if temperature > 15 and temperature < 18:
frequency = 3
duty = 102
duty_cycle = 10
pulse(frequency, duty, duty_cycle)
elif temperature > 18 and temperature < 21:
frequency = 7
duty = 306
duty_cycle = 30
pulse(frequency, duty, duty_cycle)
elif temperature > 21 and temperature < 24:
frequency = 4
duty = 767
duty_cycle = 75
pulse(frequency, duty, duty_cycle)
elif temperature > 24:
frequency = 5
duty = 200
duty_cycle = 50
pulse(frequency, duty, duty_cycle)
while True:
dht22.measure()
temperature = dht22.temperature()
humidity = dht22.humidity()
LED(temperature)