Multiple.ino 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #include <DS18B20.h>
  2. DS18B20 ds(2);
  3. void setup() {
  4. Serial.begin(9600);
  5. Serial.print("Devices: ");
  6. Serial.println(ds.getNumberOfDevices());
  7. Serial.println();
  8. }
  9. void loop() {
  10. while (ds.selectNext()) {
  11. switch (ds.getFamilyCode()) {
  12. case MODEL_DS18S20:
  13. Serial.println("Model: DS18S20/DS1820");
  14. break;
  15. case MODEL_DS1822:
  16. Serial.println("Model: DS1822");
  17. break;
  18. case MODEL_DS18B20:
  19. Serial.println("Model: DS18B20");
  20. break;
  21. default:
  22. Serial.println("Unrecognized Device");
  23. break;
  24. }
  25. uint8_t address[8];
  26. ds.getAddress(address);
  27. Serial.print("Address:");
  28. for (uint8_t i = 0; i < 8; i++) {
  29. Serial.print(" ");
  30. Serial.print(address[i]);
  31. }
  32. Serial.println();
  33. Serial.print("Resolution: ");
  34. Serial.println(ds.getResolution());
  35. Serial.print("Power Mode: ");
  36. if (ds.getPowerMode()) {
  37. Serial.println("External");
  38. } else {
  39. Serial.println("Parasite");
  40. }
  41. Serial.print("Temperature: ");
  42. Serial.print(ds.getTempC());
  43. Serial.print(" C / ");
  44. Serial.print(ds.getTempF());
  45. Serial.println(" F");
  46. Serial.println();
  47. }
  48. delay(10000);
  49. }