import tm1637
from machine import Pin
from time import sleep, localtime
#import dht
from dht import DHT22 # if the sensor is DHT11, import DHT11 instead of DHT22
tm = tm1637.TM1637(clk=Pin(4), dio=Pin(5))
# creating a DHT object
# change DHT22 to DHT11 if DHT11 is used
dht22_sensor = DHT22(Pin(16))
tm.show(" ")
timenow=localtime()
print(timenow)
while True:
dht22_sensor.measure()
temperature = dht22_sensor.temperature()
humidity = dht22_sensor.humidity()
print(temperature, humidity)
sleep(1)
temp = int(temperature)
hum = int(humidity)
tm.temperature(temp)
sleep(2)
tm.number(hum)
sleep(2)
yr=timenow[0]
mo=timenow[1]
date=timenow[2]
hr=timenow[3]
minute=timenow[4]
print(yr, mo, date, hr, minute)
tm.number(yr)
sleep(2)
tm.numbers(mo,date)
sleep(2)
tm.numbers(hr,minute)
sleep(2)
"""
# continuously get sensor readings while the board has power
while True:
# getting sensor readings
dht22_sensor.measure()
temp = dht22_sensor.temperature()
hum = dht22_sensor.humidity()
# displaying values to the console
print(f"Temperature: {temp}°C Humidity: {hum}% ")
# format method or string concatenation may also be used
#print("Temperature: {}°C Humidity: {:.0f}% ".format(temp, hum))
#print("Temperature: " + str(temp) + "°C" + " Humidity: " + str(hum) + "%")
#print("Temperature: {}°C Humidity: {:.0f}% ".format(temp, hum))
# delay of 2 secs because DHT22 takes a reading once every 2 secs
sleep(2)
"""