Advertisement
kris83

ds18b20_odczyt_adresu

Nov 13th, 2021
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3.  
  4. // Data wire is plugged into port 2 on the Arduino
  5. #define ONE_WIRE_BUS 53
  6.  
  7. // Setup a oneWire instance to communicate with any OneWire devices
  8. OneWire oneWire(ONE_WIRE_BUS);
  9.  
  10. // Pass our oneWire reference to Dallas Temperature.
  11. DallasTemperature sensors(&oneWire);
  12.  
  13. // variable to hold device addresses
  14. DeviceAddress Thermometer;
  15.  
  16. int deviceCount = 0;
  17.  
  18. void setup(void)
  19. {
  20. // start serial port
  21. Serial.begin(9600);
  22.  
  23. // Start up the library
  24. sensors.begin();
  25.  
  26. // locate devices on the bus
  27. Serial.println("Locating devices...");
  28. Serial.print("Found ");
  29. deviceCount = sensors.getDeviceCount();
  30. Serial.print(deviceCount, DEC);
  31. Serial.println(" devices.");
  32. Serial.println("");
  33.  
  34. Serial.println("Printing addresses...");
  35. for (int i = 0; i < deviceCount; i++)
  36. {
  37. Serial.print("Sensor ");
  38. Serial.print(i+1);
  39. Serial.print(" : ");
  40. sensors.getAddress(Thermometer, i);
  41. printAddress(Thermometer);
  42. }
  43. }
  44.  
  45. void loop(void)
  46. {}
  47.  
  48. void printAddress(DeviceAddress deviceAddress)
  49. {
  50. for (uint8_t i = 0; i < 8; i++)
  51. {
  52. Serial.print("0x");
  53. if (deviceAddress[i] < 0x10) Serial.print("0");
  54. Serial.print(deviceAddress[i], HEX);
  55. if (i < 7) Serial.print(", ");
  56. }
  57. Serial.println("");
  58. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement