Advertisement
Krzyspx

Moja biblioteka obsługi DS18B20

Aug 16th, 2017
534
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. #include <OneWire.h>
  2. #define ONE_WIRE_BUS 13 // 1-Wire bus Arduino pin
  3. OneWire oneWire(ONE_WIRE_BUS);
  4. #include <DallasTemperature.h>
  5. DallasTemperature sensors(&oneWire);
  6. DeviceAddress tempDeviceAddress;
  7.  
  8. String tempstr="";
  9. int oldtemp = 0;
  10. void sensorT() { //wysylanie ttemp do APP
  11.   int tempx10 = (((sensors.getTempCByIndex(0)) * 10) - 30); // x 10 i kalibracja
  12.  
  13.   sensors.setWaitForConversion(false);  // makes it async
  14.   sensors.requestTemperatures(); // Send the command to get temperatures
  15.   int temperature = (tempx10 / 10);
  16.   int dziesietne = (tempx10 % 10);
  17.   String str = String(temperature) + "." + String(dziesietne) + " ℃"; // oszczedzam 3 kB pamieci
  18.  tempstr=str;
  19.   Serial.println("realtemp" + str);
  20.     Blynk.virtualWrite(V3, temperature);
  21.  
  22.   if (oldtemp != tempx10) {
  23.     oldtemp = tempx10;
  24.     Blynk.virtualWrite(V2, str);
  25.   }
  26. }
  27. void setdallas() //ustawienia początkowe dla Dallas
  28. {
  29.   sensors.begin();// Dallas
  30.   sensors.getAddress(tempDeviceAddress, 0);
  31.   sensors.setResolution(tempDeviceAddress, 12);
  32.   sensors.setWaitForConversion(false);  // makes it async
  33.   sensors.requestTemperatures(); // Send the command to get temperatures
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement