import machine, time, onewire, ds18x20
from ssd1306 import SSD1306_I2C
svetlomodra_led = machine.Pin(25, machine.Pin.OUT)
zelena_led = machine.Pin(26, machine.Pin.OUT)
cervena_led = machine.Pin(27, machine.Pin.OUT)
modra_led = machine.Pin(33, machine.Pin.OUT)
i2c = machine.I2C(0, scl=machine.Pin(22), sda=machine.Pin(21))
oled = SSD1306_I2C(128, 64, i2c)
ds_pin = machine.Pin(4)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))
roms = ds_sensor.scan()
while True:
ds_sensor.convert_temp()
time.sleep_ms(500)
teplota = ds_sensor.read_temp(roms[0])
oled.fill(0)
oled.text("Teplota:", 0, 0)
oled.text(f"{teplota:.2f} C", 0, 10) # zobrazenie teploty na dve desatinne miesta
oled.show()
if teplota < 0:
modra_led.on()
svetlomodra_led.off()
zelena_led.off()
cervena_led.off()
elif teplota >= 0 and teplota < 20:
modra_led.off()
svetlomodra_led.on()
zelena_led.off()
cervena_led.off()
elif teplota >= 20 and teplota <= 30:
modra_led.off()
svetlomodra_led.off()
zelena_led.on()
cervena_led.off()
else:
modra_led.off()
svetlomodra_led.off()
zelena_led.off()
cervena_led.on()
time.sleep(1)