#MicroPython动手做(34)——通用传感器的综合运用
#DHT11温湿度传感器
from mpython import *
import network
import ntptime
import time
import music
from machine import Timer
import dht
my_wifi = wifi()
my_wifi.connectWiFi("zh", "zy1567")
dht11 = dht.DHT11(Pin(Pin.P15))
tim13 = Timer(13)
def timer13_tick(_):
try: dht11.measure()
except: pass
tim13.init(period=1000, mode=Timer.PERIODIC, callback=timer13_tick)
ntptime.settime(8, "time.windows.com")
rgb[1] = (int(0), int(102), int(0))
rgb.write()
time.sleep_ms(1)
music.play('E5:1')
while True:
oled.fill(0)
oled.DispChar("温湿度表", 0, 0, 1)
oled.DispChar((''.join([str(x) for x in [time.localtime()[1], "月", time.localtime()[2], "日", time.localtime()[3], "时", time.localtime()[4], "分", time.localtime()[5], "秒 "]])), 0, 14, 1)
oled.DispChar((str("温度:") + str(dht11.temperature())), 0, 30, 1)
oled.DispChar((str("湿度:") + str(dht11.humidity())), 0, 44, 1)
oled.show()
|