|
|
以下为代码:
from mpython import *
from machine import Timer
import dht
import time
dht11 = dht.DHT11(Pin(Pin.P0))
tim13 = Timer(13)
def timer13_tick(_):
try: dht11.measure()
except: pass
tim13.init(period=1000, mode=Timer.PERIODIC, callback=timer13_tick)
while True:
温度 = dht11.temperature()
湿度 = dht11.humidity()
oled.fill(0)
oled.DispChar(str((''.join([str(x) for x in ['当前温度:', 温度, '℃']]))), 0, 0, 1)
oled.DispChar(str((''.join([str(x2) for x2 in ['当前湿度:', 湿度, '%RH']]))), 0, 16, 1)
oled.show()
time.sleep(1)
(其实就是例程)
|
|