Code: Select all
def Temperature(resolution, dsPin):
dat = machine.Pin(dsPin)
ds = DS18X20(onewire.OneWire(dat))
roms = ds.scan()
for rom in roms:
if resolution == 9:
config = b'\x00\x00\x1f'
if resolution == 10:
config = b'\x00\x00\x3f'
if resolution == 11:
config = b'\x00\x00\x5f'
if resolution == 12:
config = b'\x00\x00\x7f'
ds.write_scratch(rom, config)
ds.convert_temp()
time.sleep_ms(int(750 / (2** (12 - resolution))))
t = 0
for rom in roms:
t = ds.read_temp(rom)
return t