from machine import Pin,SoftI2C,Timer
import onewire,ds18x20,time
import ssd1306
i2c=SoftI2C(sda=Pin(21),scl=Pin(22))
oled ssd1306.SSD1306_I2C(128,64,i2c)
red = Pin(2,Pin.OUT)
green=Pin(4,Pin.OUT)
blue=Pin(16,Pin.OUT)
ow=onewire.OneWire(Pin(15))
ds=ds18x20.DS18X20(ow)
rom=ds.scan()
def temp_gat(tim):
ds.convert_temp()
temp=ds.read_temp(rom[0])
oled.fill(0)
oled.text(str('%2f'%temp),0,0)
oled.show()
if temp<50:
red.value(0)
green.value(1)
blue.value(0)
if temp>50:
red.value(1)
green.value(0)
blue.value(0)
tim=Timer(-1)
tim.init(period=300,mode=Timer.PERIODIC,callback=temp_gat)