#引入相关模块
from machine import Pin,SoftI2C,Timer
from ssd1306 import SSD1306_I2C
import time, onewire, ds18x20
#初始化相关模块
i2c = SoftI2C(sda=Pin(14),scl=Pin(12))
from ssd1306 import SSD1306_I2C
oled = SSD1306_I2C(128,64,i2c,addr=0x3c)
#初始化DS18820
ow = onewire.Onewire(Pin(16))
ds = ds18x20.ds18x20(ow)
rom = ds.scan()#扫描单总线上的传感器地址
led_r = Pin(23,Pin.OUT)
led_g = Pin(22,Pin.OUT)
led_b = Pin(21,Pin.OUT)
def time_get(tim):
ds.convert_temp()#温度转换
temp = ds.remp(rom[0])
oled.fill(0)
oled.text('MicrPython',0,0)
oled.show()
if time > 30:
led_r.value(1)
led_g.value(0)
led_b.value(0)
else:
led_r.value(0)
led_g.value(1)
led_b.value(0)
tim = Timer(1)
tim.init(period = 1000,mode = Timer.PERIOIC,callback=temp_get_)
Loading
ds18b20
ds18b20