Simple.pde 927 B

123456789101112131415161718192021222324252627282930313233
  1. #include <OneWire.h>
  2. #include <DallasTemperature.h>
  3. // Data wire is plugged into port 2 on the Arduino
  4. #define ONE_WIRE_BUS 2
  5. // Setup a oneWire instance to communicate with any OneWire devices (not just Maxim/Dallas temperature ICs)
  6. OneWire oneWire(ONE_WIRE_BUS);
  7. // Pass our oneWire reference to Dallas Temperature.
  8. DallasTemperature sensors(&oneWire);
  9. void setup(void)
  10. {
  11. // start serial port
  12. Serial.begin(9600);
  13. Serial.println("Dallas Temperature IC Control Library Demo");
  14. // Start up the library
  15. sensors.begin();
  16. }
  17. void loop(void)
  18. {
  19. // call sensors.requestTemperatures() to issue a global temperature
  20. // request to all devices on the bus
  21. Serial.print("Requesting temperatures...");
  22. sensors.requestTemperatures(); // Send the command to get temperatures
  23. Serial.println("DONE");
  24. Serial.print("Temperature for the device 1 (index 0) is: ");
  25. Serial.println(sensors.getTempCByIndex(0));
  26. }