Advertisement
harrisonhjones

Untitled

Mar 7th, 2015
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include "DS18B20.h"
  2. #include "OneWire.h"
  3.  
  4. DS18B20 ds18b20 = DS18B20(D2);
  5. char szInfo[64];
  6.  
  7. unsigned long _time = 0;
  8.  
  9. void setup() {
  10.     Serial1.begin(9600);
  11. }
  12.  
  13. void loop() {
  14.     if(!ds18b20.search()) {
  15.         Serial1.println("No more addresses.");
  16.         Serial1.println();
  17.         ds18b20.resetsearch();
  18.         delay(250);
  19.         return;      
  20.     }
  21.     if((millis() - _time) > 1000)
  22.     {
  23.         _time = millis();
  24.         float celsius = ds18b20.getTemperature();
  25.         sprintf(szInfo, "Temperature: %2.2f Celsius, (Chip Name: %s)", celsius, ds18b20.getChipName());
  26.         Spark.publish("tmpinfo", szInfo);
  27.     }
  28. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement