SetUserData.ino 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. //
  2. // This sketch does not use the ALARM registers and uses those 2 bytes as a counter
  3. // these 2 bytes can be used for other purposes as well e.g. last temperature or
  4. // a specific ID.
  5. //
  6. #include <OneWire.h>
  7. #include <DallasTemperature.h>
  8. // Data wire is plugged into port 2 on the Arduino
  9. #define ONE_WIRE_BUS 2
  10. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  11. OneWire oneWire(ONE_WIRE_BUS);
  12. // Pass our oneWire reference to Dallas Temperature.
  13. DallasTemperature sensors(&oneWire);
  14. int count = 0;
  15. void setup(void)
  16. {
  17. // start serial port
  18. Serial.begin(9600);
  19. Serial.println("Dallas Temperature IC Control Library Demo");
  20. // Start up the library
  21. sensors.begin();
  22. }
  23. void loop(void)
  24. {
  25. // call sensors.requestTemperatures() to issue a global temperature
  26. // request to all devices on the bus
  27. Serial.print("Requesting temperatures...");
  28. sensors.requestTemperatures(); // Send the command to get temperatures
  29. Serial.println("DONE");
  30. Serial.print("Temperature for the device 1 (index 0) is: ");
  31. Serial.println(sensors.getTempCByIndex(0));
  32. count++;
  33. sensors.setUserDataByIndex(0, count);
  34. int x = sensors.getUserDataByIndex(0);
  35. Serial.println(count);
  36. }