Advertisement
arekem

Untitled

Feb 2nd, 2019
226
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.25 KB | None | 0 0
  1. //#define CAYENNE_DEBUG       // Uncomment to show debug messages
  2. #define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
  3. #include <CayenneMQTTEthernet.h>
  4. #include <Wire.h>
  5. #include <LiquidCrystal_PCF8574.h>
  6. #include <OneWire.h>
  7. #include <DS18B20.h>
  8.  
  9. // Cayenne authentication info. This should be obtained from the Cayenne Dashboard.
  10. char username[] = "removed";
  11. char password[] = "removed";
  12. char clientID[] = "removed";
  13.  
  14. #define ONEWIRE_PIN 3
  15.  
  16. #define SENSORS_NUM 2
  17.  
  18. const byte address[SENSORS_NUM][8] PROGMEM = {
  19. 0x28, 0xFF, 0xA0, 0xD0, 0x47, 0x16, 0x3, 0x95,
  20. 0x28, 0xFF, 0x73, 0x12, 0x47, 0x16, 0x3, 0xBB
  21. };
  22.  
  23. OneWire onewire(ONEWIRE_PIN);
  24. DS18B20 sensors(&onewire);
  25.  
  26. LiquidCrystal_PCF8574 lcd(0x27);  // set the LCD address to 0x27 for a 16 chars and 2 line display
  27.  
  28. int show;
  29. int error;
  30. float temperature0;
  31. float temperature1;
  32.  
  33. void setup() {
  34.   Serial.begin(115200);
  35.   Serial.println("LCD...");
  36.  
  37.   while (! Serial);
  38.  
  39.   Serial.println("Dose: check for LCD");
  40.  
  41.   // See http://playground.arduino.cc/Main/I2cScanner
  42.   Wire.begin();
  43.   Wire.beginTransmission(0x27);
  44.   error = Wire.endTransmission();
  45.   Serial.print("Error: ");
  46.   Serial.print(error);
  47.  
  48.   if (error == 0) {
  49.     Serial.println(": LCD found.");
  50.  
  51.   } else {
  52.     Serial.println(": LCD not found.");
  53.   } // if
  54.  
  55.   lcd.begin(16, 2); // initialize the lcd
  56.   show = 0;
  57.  
  58.   Serial.begin(9600);
  59.  
  60.   sensors.begin();
  61.   sensors.request();
  62.   Cayenne.begin(username, password, clientID);
  63.  
  64. }
  65.  
  66. CAYENNE_OUT(V0)
  67. {
  68.   Cayenne.virtualWrite(V0, temperature0); //virtual pin
  69. }
  70.  
  71. CAYENNE_OUT(V1)
  72. {
  73.   Cayenne.virtualWrite(V1, temperature1); //virtual pin
  74. }
  75.  
  76. void loop() {
  77.  
  78.   lcd.setBacklight(255);    
  79.  
  80.     if (sensors.available())
  81.     {
  82.           temperature0 = sensors.readTemperature(FA(address[0]));
  83.           temperature1 = sensors.readTemperature(FA(address[1]));
  84.  
  85.           lcd.home(); lcd.clear();
  86.           lcd.setCursor(0, 0);
  87.           lcd.print(F("Zasilanie "));
  88.           lcd.print(temperature0);
  89.           lcd.print(F("C"));
  90.           lcd.setCursor(0, 1);
  91.           lcd.print(F("Powrot    "));
  92.           lcd.print(temperature1);
  93.           lcd.println(F("C"));
  94.           delay(5000);
  95.  
  96.     sensors.request();
  97.   }
  98.  
  99.   Cayenne.loop();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement