commit 2dcb6948ff65df28fbfa8f5d288cedab13080059 Author: Jakub Tuček Date: Fri Feb 27 09:37:27 2026 +0100 Upload files to "/" diff --git a/dallas.ino b/dallas.ino new file mode 100644 index 0000000..956c26a --- /dev/null +++ b/dallas.ino @@ -0,0 +1,65 @@ +#include +#include + +#define ONE_WIRE_BUS 8 // Pin, kde je připojen DS18B20 + +OneWire oneWire(ONE_WIRE_BUS); +DallasTemperature sensors(&oneWire); + +DeviceAddress sensorAddress; +bool sensorFound = false; + +void printAddress(DeviceAddress deviceAddress) { + for (uint8_t i = 0; i < 8; i++) { + if (deviceAddress[i] < 16) Serial.print("0"); + Serial.print(deviceAddress[i], HEX); + } +} + +void setup() { + pinMode(8, INPUT_PULLUP); + Serial.begin(115200); + delay(2000); + + Serial.println("Hledám DS18B20..."); + + sensors.begin(); + + if (sensors.getDeviceCount() == 0) { + Serial.println("Žádné čidlo nenalezeno!"); + return; + } + + if (sensors.getAddress(sensorAddress, 0)) { + sensorFound = true; + Serial.print("Čidlo nalezeno, adresa: "); + printAddress(sensorAddress); + Serial.println(); + + sensors.setResolution(sensorAddress, 12); // 9–12 bitů + } else { + Serial.println("Nepodařilo se získat adresu čidla."); + } +} + +void loop() { + + if (!sensorFound) { + delay(2000); + return; + } + + sensors.requestTemperatures(); + + float temperature = sensors.getTempC(sensorAddress); + + if (temperature == DEVICE_DISCONNECTED_C) { + Serial.println("Čidlo odpojeno!"); + } else { + Serial.print("Teplota: "); + Serial.print(temperature); + Serial.println(" °C"); + } + + delay(2000); +} \ No newline at end of file diff --git a/teplotni cidlo Dallas.jpg b/teplotni cidlo Dallas.jpg new file mode 100644 index 0000000..d126147 Binary files /dev/null and b/teplotni cidlo Dallas.jpg differ