Advertisement
Krzyspx

brama3.5main

Dec 2nd, 2016
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 5.91 KB | None | 0 0
  1. /*******************************************************************
  2.   V1 - vLED OK - tak
  3.   V2 - VLED przełącznik
  4.   V29 - Terminal
  5.   V6 - show temp DS
  6.   V10 - on/off menu pilot
  7.   V11 - menu pilot
  8.   V12 - button on/off
  9.   v13 - gate open/close
  10.   V15 - pompa on
  11.   V16 timer pompy
  12.  
  13.   A5 - przełącznik
  14.   13 - DS18b20
  15.   11 transoptor
  16.   #ifndef
  17. #define
  18. ********************************************************************/
  19.  
  20. #include "klaw.h"
  21. #include "transmit.h"
  22. #include "dallas.h"
  23. #include "pompa.h"
  24.  
  25. #include <OneWire.h>
  26. #include <DallasTemperature.h>
  27. #include <RCSwitch.h>
  28.  
  29. #include <Timers.h> //  my favorite timer
  30. Timers <6> akcja; //
  31.  
  32. #define led_green 7  // przyłączenia do fizycznych portów NANO
  33. #define led_red   8 //
  34. #define przelacznik A5
  35. #define resetesp  4
  36. #define pilotbrama  11
  37.  
  38.  
  39.  
  40. //zmienne globalne
  41.  
  42. int sendnotifi = 0; //wyślij noti
  43. int sendemail = 0;  // wyślij email
  44.  
  45. //>>>>>>>>>>>>>>>>>>> my NANO Programs
  46.  
  47. void setupstart() { //początkowe ustawienia widgetow
  48.   BlynkvirtualWrite_col(30, _GREEN);
  49.   BlynkvirtualWrite_col(1, BLYNK_GREEN);
  50.   BlynkvirtualWrite_col(2, _RED);
  51.   BlynkvirtualWrite_col(10, _BLUE);
  52.   BlynkvirtualWrite_col(11, _BLUE);
  53.   BlynkvirtualWrite_col(12, _MAGENTA);
  54.   BlynkvirtualWrite_col(15, _YELLOW);
  55. }
  56. void setupstart2()
  57. {
  58.   BlynkvirtualWrite_Off(10, "PILOT");
  59.   BlynkvirtualWrite_On(10, "PILOT");
  60.   BlynkvirtualWrite_On(12, "k1");
  61.   BlynkvirtualWrite_Off(12, "k1");
  62.   BlynkvirtualWrite_On(15, "POMPA");
  63.   BlynkvirtualWrite_Off(15, "POMPA");
  64. }
  65.  
  66. byte ESPonline = 10; //licznik watchdog dla esp
  67. byte flagasetup1 = 0; //czy wysłać dane początkowe z APP
  68. void Program_vPin0(String strvPin) {
  69.   digitalWrite(led_red, intfromstr(strvPin));  //miganie led red przez ESP
  70.   ESPonline = 10;
  71.   if (flagasetup1 == 0) {
  72.     flagasetup1 = 1;
  73.     BlynkvirtualWrite_order(1, "a");
  74.   }
  75. }
  76. void Program_vPin10(String strvPin) {
  77.   sendkodpilot(jakikod(menupilot, intfromstr(strvPin)), impuls_pilot); // wysyła kod z pozycji menupilot i on/off zależne od ppolot
  78.   //    BlynkvirtualWrite_order(2, "to ja blynk");
  79.   //   akcja.updateInterval(3, 500);
  80. }
  81. void Program_vPin11(String strvPin) {
  82.   menupilot = intfromstr(strvPin);
  83. }
  84. void Program_vPin12(String strvPin) {
  85.   sendkodpilot(jakikod(1, intfromstr(strvPin)), impuls_pilot);  //wysyła kod z 1 pozycji menu on lub off
  86.   //  BlynkvirtualWrite_order(10, "500");
  87.   //  akcja.updateInterval(3, 1500);
  88. }
  89. void Program_vPin13(String strvPin) {//pilot brama
  90.   sterujbrama(intfromstr(strvPin)); // zmiana stanu pin 11 - naciskanie pilota bramy
  91. }
  92. void Program_vPin15(String strvPin) {
  93.   pomparunprzycisk(strvPin);
  94. }
  95. void Program_vPin16(String strvPin) {
  96.   timerpompa(strvPin);
  97. }
  98. void Program_vPin29(String strvPin) {}
  99.  
  100. void Program_vPin34(String strvPin) {
  101.   if (intfromstr(strvPin)) termesp = 1; else termesp = 0;
  102. }
  103.  
  104. int intfromstr(String str) {
  105.   String    strdata3 = str.substring(str.indexOf(':') + 1);  // if nr vPin typ int
  106.   return strdata3.toInt();
  107. }
  108.  
  109.  
  110. //>>>>>>>>>>>>>>>>>>>>>>>> gate
  111.  
  112. void infgateopen() { //czujnik otwarcia bramy
  113.   // BlynkvirtualWrite_col(8, _RED);
  114.   // BlynkvirtualWrite_str(8, "BRAMAA OPEN");
  115.   BlynkvirtualWrite_Off(13, "BR OPEN");
  116.   BlynkvirtualWrite_col(13, _RED);
  117.  
  118. }
  119. void infgateclose() {
  120.   // BlynkvirtualWrite_col(8, _GREEN);
  121.   // BlynkvirtualWrite_str(8, "BRAMAA CLOSE");
  122.   BlynkvirtualWrite_Off(13, "BR CLOSE");
  123.   BlynkvirtualWrite_col(13, _GREEN);
  124. }
  125.  
  126. void  sterujbrama(int stanvPin) //steroanie pilotem bramy
  127. {
  128.   if (stanvPin) {
  129.     digitalWrite(pilotbrama, HIGH);
  130.      akcja.updateInterval(3, 300); //led green miga szybko gdy naciśnięty VPin bramy
  131.   } else {
  132.     digitalWrite(pilotbrama, LOW);
  133.      akcja.updateInterval(3, 2000);
  134.   }
  135. }
  136. //ssssssssssssssssssssssssssssssssssssssssssss
  137. void setup()
  138. {
  139.   pinMode(led_red, OUTPUT); //test
  140.   pinMode(led_green, OUTPUT); //test
  141.   pinMode(przelacznik, INPUT_PULLUP);
  142.   digitalWrite(led_green, HIGH);
  143.   digitalWrite(led_red, HIGH);
  144.   pinMode(pilotbrama, OUTPUT);
  145.   digitalWrite(pilotbrama, LOW);
  146.  
  147.   Serial.begin(115200);
  148.   delay(100);
  149.   Serial.println(F(__FILE__));  //BLYNK .3.10 Arduino IDE.cc 1.6.12
  150.   setupstart();
  151.   delay(1000);
  152.   setupstart2();
  153.   delay(1000);
  154.  
  155.   akcja.attach(0, 2000, timer1sek); //  5 sek
  156.   akcja.attach(1, 10000, licznikobiegu); // pętla dłuższa 10 s licznik grzania
  157.   akcja.attach(2, 20000, notemail); //by nie wysyłać za częto emaili i noti
  158.   akcja.attach(3, 2000, timerled); //  
  159.  
  160.   setrcswitch(); //setup for rcswitch
  161.   setdallas(); //setup for ds18b20
  162.  
  163.   flagasetup1 = 0; //flaga do jednokrotnego wysłania aktualnych stanów vPinów z APP
  164. }
  165.  
  166. void loop()
  167. {
  168.   akcja.process(); // timer
  169.   recivestrfromserial(); //dekodowanie danych z serial
  170.   kod_run(); //analiza odbioru 433 MHz
  171. }
  172.  
  173. void notemail() {// wysyłanie emaili i noti
  174.   if (sendnotifi) {
  175.     sendnotifi = 0;
  176.     BlynkvirtualWrite_order(2, "noti od BLYNKa");
  177.   }
  178.   if (sendemail) {
  179.     sendemail = 0;
  180.     BlynkvirtualWrite_order(3, "Email od BLYNKa");
  181.   }
  182. }
  183.  
  184. void timer1sek() { //różne rzeczy wykonywane cyklicznie
  185.  
  186.   blinkvLed2(); //blink vLed from NANO
  187.   testprzelacznik();
  188.   watchdogESP();  //watchdog for ESP
  189.   sensorT();    //dallas
  190.   oldrecivecod = 0; // by nie wysyłać za często powtarzających się kodów
  191. }
  192.  
  193. void timerled() {// osobny timer dla leda green
  194.   blinkLedgreen(); // blink led on NANO
  195. }
  196.  
  197. void watchdogESP () { //watchdogdla esp
  198.   ESPonline--;
  199. }
  200. void testprzelacznik() { //sprawdzanie stany przełącznika
  201.   if (!digitalRead(przelacznik)) {
  202.     BlynkvirtualWrite_led(2, 255);
  203.   }
  204.   else {
  205.     BlynkvirtualWrite_led(2, 0);
  206.   }
  207. }
  208.  
  209. bool flagaled = 0; //blink NANO led NANO
  210. void blinkLedgreen() {
  211.   flagaled = !flagaled;
  212.   digitalWrite(led_green, flagaled);
  213. }
  214. bool flagaled2 = 0;
  215. void blinkvLed2() {
  216.   flagaled2 = !flagaled2;
  217.   if (flagaled2)  {
  218.     BlynkvirtualWrite_led(1, 255); //blink NANO in APP
  219.   }
  220.   else   {
  221.     BlynkvirtualWrite_led(1, 0);
  222.   }
  223. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement