Advertisement
Krzyspx

brama1

May 29th, 2016
2,582
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.94 KB | None | 0 0
  1. //#define BLYNK_DEBUG
  2. // ok działa transmisja z Blynk i dioda na 7 porty 11,9 18b20 na A5
  3.  
  4. #include "Arduino.h"
  5. #define BLYNK_PRINT Serial  // Comment this out to disable prints and save space
  6. #include <ESP8266_HardSer.h>
  7. #include <BlynkSimpleShieldEsp8266_HardSer.h>
  8. #include <Adafruit_SleepyDog.h>
  9. #include <OneWire.h>
  10. #include <DS18B20.h>
  11.  
  12.  
  13.  
  14. WidgetLED led1(V1); // vLED wskażnik połącznia z arduino - miga co 1 sek jeśli jest połączenie
  15. WidgetLED led5(V5); //wskaznik pilota 1
  16. WidgetLED led6(V6);//wskaznik pilota 2
  17.  
  18. #define EspSerial Serial // Set ESP8266 Serial object
  19. ESP8266 wifi(EspSerial);
  20.  
  21.  
  22. char auth[] = "ooooooooooooooooooooooooooooooooooooooo";
  23. const byte ONEWIRE_PIN = A5; // 1-Wire bus Arduino pin
  24. byte sensorAddress[8] = {0x28, 0xFF, 0xAE, 0x1B, 0x5, 0x16, 0x3, 0xE4};
  25. const int ledPinA4 =  7; //dioda sygnalizacyjna połączenia z BLYNK serwerwm połączona jest też z z vprzyciskiem bezpośrednim dla celów testowych
  26. const int button1Pin = 8;  //we przycisku
  27. OneWire onewire(ONEWIRE_PIN); // 1-Wire object
  28. DS18B20 sensors(&onewire); // DS18B20 sensors object
  29. float temperature = 0;
  30. float temperature1 = 0;
  31. int temp1 = 0;
  32. int ledStateA4 = HIGH;
  33. int tbutton1 = 0;
  34.  
  35. int V3_down = 0;
  36.  
  37. int ppilot = 0;
  38. int ppilotold = 0;
  39. int vPin20 = 0; // z vMENU
  40. int onoff = 0;
  41. int klaw1stan = 0;
  42. int wskrunAr = 0; //vLED miga co sek
  43. int timer1 = 0; // co 1 sek
  44. int treset = 0; //czas analizy połaczenia z BLYNK
  45. int sekunda = 0; //zmienna pomocnicza do pompy
  46.  
  47.  
  48. void setup()
  49. {
  50.   pinMode(ledPinA4, OUTPUT); // dioda sygnalizacyjna czy uruchomiło się połączenie z serwerem BLYNK - nie świeci gdy NIE ma połaczenia
  51.   digitalWrite(ledPinA4, LOW);
  52.   sensors.begin();  // DS18B20 sensors setup
  53.   sensors.request(sensorAddress);  // Requests sensor for measurement
  54.  
  55.   Serial.begin(115200);  // Set console baud rate
  56.   delay(10);
  57.    EspSerial.begin(115200);  // Set ESP8266 baud rate
  58.   delay(10);
  59.   Blynk.begin(auth, wifi, "123","a1b2c3d4");
  60.  
  61.     while (Blynk.connect() == false) {}   // Wait until Blynk is connected
  62.  
  63.       pinMode(button1Pin, INPUT_PULLUP);   //  Blynk.virtualWrite(V5, 0); przycisk na porcie 8 połączony z vLED na V5
  64.   treset = millis() / 1000; // pętla 1 sek - do sprawdzania pocedury BLYNK Conected
  65.    
  66. } // koniec pęli setup
  67.  
  68. bool isFirstConnect = true;
  69. // This function will run every time Blynk connection is established
  70. BLYNK_CONNECTED() {
  71.   ledStateA4 = LOW;
  72.   digitalWrite(ledPinA4, HIGH);  //zgaszenie LED gdy jest połaczenie z BLYNK server
  73.   if (isFirstConnect) {
  74.     Blynk.syncAll();  //ważna procedura - po starcie arduino synchronizuje wszystkiw wirtualne piny ze zmiennymi programu
  75.     isFirstConnect = false;
  76.   }
  77. }
  78. BLYNK_WRITE(V10) //vprzycisk załączenia pompy
  79. {
  80. //  pompaonoff = param.asInt();
  81. }
  82.  
  83. BLYNK_WRITE(V3) //vprzycisk do pilotów on/off
  84. {
  85.   //  BLYNK_LOG("V3=%s", param.asStr());
  86.   ppilot = param.asInt();
  87. }
  88. BLYNK_WRITE(V20) //wybór pilota - menu rozwijane
  89. {
  90.   vPin20 = param.asInt();
  91. }
  92. BLYNK_READ(V11) //temperatura
  93. {
  94.   String str = String(temperature, 1) + " ℃";
  95.   Blynk.virtualWrite(V11, str);
  96. }
  97.  
  98. void loop()
  99. {
  100.   Blynk.run();
  101.    int i = millis() / 1000; //co 2 sekundy coś możemy robić
  102.   if ((i - treset) > 1) {  // co 2 sek sprawdzenie czy jest połączenie z BLYNK
  103.     treset = millis() / 1000;
  104.     bool r = Blynk.connected();
  105.     if (r == 1) { //jeśli jest połączenie to zgaś LED
  106.       digitalWrite(ledPinA4, HIGH);
  107.  
  108.     }
  109.     else {
  110.       digitalWrite(ledPinA4, LOW); // jeśli nie ma to zapal LED
  111.       Watchdog.enable(2000); // za dwie sek restar procesora
  112.     }
  113.   } // koniec procedury testowania połączenia BLYNK
  114.  
  115.     if (ppilot == ppilotold) {} //sprawdzanie zmiany stanu przycisku  vPIN pilot (V3)
  116.   else {
  117.     V3_down = 1; //jest zmiana stanu klawisza vPin3
  118.     ppilotold = ppilot;
  119.   }
  120.       if ((V3_down == 1)) {
  121.    onoff = ppilot; //zapisanie stanu klawisza do wysłania kodu on/off
  122.  
  123.     if (onoff == 1) {
  124.     led6.on(); //wysłanie potwierdzenia na vLED o on/off komendzie pilota
  125.     }
  126.     else {
  127.     led6.off();
  128.     }
  129.    
  130.     V3_down = 0;
  131.    
  132.   }
  133.   int j = millis() / 1000; //co 2 sekundy sprawdzanie przycisku na porcie 8
  134.    if ((j - timer1) > 1) {
  135.      klaw1stan = digitalRead(button1Pin);
  136.      if (klaw1stan == 0){
  137.       // led5.on(); //zapalenie vLED gdy przycisk wciśniety
  138.      }
  139.      else {
  140.     //   led5.off();
  141.      }
  142.    wskrunAr = !wskrunAr ;
  143.     if (wskrunAr == 0){
  144.       led1.off(); //miganie vLED dla kontroli połączenia z UNO
  145.     }
  146.    else {
  147.      led1.on();
  148.    }
  149. timer1 = j;  
  150.  
  151.  if (sensors.available())
  152.   {
  153.     temperature = sensors.readTemperature(sensorAddress);    // Reads the temperature from sensor
  154.     temperature1 = (temperature*10);
  155.     temp1 = temperature1;
  156.     temperature1 = temp1;
  157.     temperature = (temperature1/10);
  158.     //Serial.print(temperature);
  159.     //Serial.println((" 'C"));
  160.     sensors.request(sensorAddress);
  161.   }
  162.  
  163.    } //koniec petli 1 sek
  164.  
  165. } //koniec loop
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement