Advertisement
Krzyspx

brama4klaw

Dec 5th, 2016
3,903
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.82 KB | None | 0 0
  1. #include <Arduino.h>
  2. #include <RCSwitch.h>
  3. RCSwitch mySwitch = RCSwitch(); //nie wiem co to - pewnie nadanie nazwy własnej procedurze
  4.  
  5. void pomparunpir();
  6. void infgateopen();
  7. void infgateclose();
  8. void BlynkvirtualWrite_str (byte vPin1, String str1);
  9.  
  10. #define BLYNK_GREEN     "#23C48E"
  11. #define BLYNK_BLUE      "#04C0F8"
  12. #define BLYNK_YELLOW    "#ED9D00"
  13. #define BLYNK_RED       "#D3435C"
  14. #define BLYNK_DARK_BLUE "#5F7CD8"
  15.  
  16. #define _RED        "#FF0000"
  17. #define _GREEN      "#00FF00"
  18. #define _MAGENTA    "#FF00FF"
  19. #define _YELLOW     "#FFFF00"
  20. #define _BLACK      "#000000"
  21. #define _WHITE      "#FFFFFF"
  22. #define _WBLUE      "#00FFFF"
  23. #define _PINK       "#FFB3B3"
  24. #define _OLIVE      "#808000"
  25. #define _BRAU       "#FF8000"
  26. #define _karmin     "#FF0080"
  27. #define _SEE        "#00FF80"
  28. #define _fiolet     "#8000FF"
  29. #define _BLUE       "#0080FF"
  30.  
  31. #define impuls_pilot 320  // dł impulsu dla pilota ELRO
  32. #define impuls_piec 210
  33.  
  34. #define k1on 5522769
  35. #define k1off 5522772
  36. #define k2on 5525841
  37. #define k2off 5525844
  38.  
  39. #define sal4on 21777
  40. #define sal4off 21780
  41.  
  42. #define ogrodAon 263505
  43. #define ogrodAoff 263508
  44. #define ogrodBon 266577
  45. #define ogrodBoff 266580
  46. #define ogrodCon 267345
  47. #define ogrodCoff 267348
  48. #define ogrodDon 267537
  49. #define ogrodDoff 267540
  50.  
  51. #define gateopen 3150041 // 400
  52. #define gateclose 13564377 // 400
  53. #define pirpompa 14013756 // delay  400
  54.  
  55. #define piecon 5592331 //5592332 delay 210
  56. #define piecoff 5592323 //5592332 delay 210
  57.  
  58. #define pompaoff 4478228 //zmienic
  59. #define pompaon  4478225
  60.  
  61. int menupilot;   // wybrana pozycja z menu
  62.  
  63. unsigned long jakikod(int mp, int pp) // tabela kodów wybieranych przez mp i pp dla menu rozwijanego
  64. {
  65.   unsigned long x;
  66.   if (pp)  {
  67.     switch (mp) { // Switch on Elro - wybór kodu pilota w zależności od ustawienia w menu rozwijanym
  68.       case 1: x = k1on;  break;
  69.       case 2: x = k2on;  break;
  70.       case 3: x = sal4on;  break;
  71.  
  72.       case 5: x = ogrodAon;  break;
  73.       case 6: x = ogrodBon;  break;      
  74.       case 7: x = ogrodCon;  break;
  75.       case 8: x = ogrodDon;  break;
  76.      
  77.       default: ;
  78.     }
  79.   } else  {
  80.     switch (mp)  { // Switch on Elro - wybór kodu pilota w zależności od ustawienia w menu rozwijanym
  81.       case 1: x = k1off;  break;
  82.       case 2: x = k2off;  break;
  83.       case 3: x = sal4off;  break;
  84.      
  85.       case 5: x = ogrodAoff;  break;
  86.       case 6: x = ogrodBoff;  break;
  87.       case 7: x = ogrodCoff;  break;
  88.       case 8: x = ogrodDoff;  break;
  89.       default: ;
  90.     }
  91.   }
  92.   return x;
  93. }
  94.  
  95. void sendkodpilot (unsigned long codeA, int len) // wysłanie kodu przez nadajnik 433MHz
  96. {
  97.   mySwitch.setPulseLength(len);
  98.   mySwitch.setProtocol(1);
  99.   mySwitch.setRepeatTransmit(4);
  100.   mySwitch.send(codeA, 24);
  101. }
  102.  
  103. void setrcswitch(){//ustawienia początkowe
  104.   mySwitch.enableReceive(0);  // Receiver on inerrupt 0 => that is pin #2
  105.   mySwitch.enableTransmit(3); // Transmiter pin D3
  106. }
  107.  
  108. bool termesp = 0; //przełącznik wyświetlania odebranych danych na vTerminalu
  109. unsigned long oldrecivecod = 0; // kod odebrany z 433MHz
  110. void  kod_run() // procedyra obsługi odebranego z 433MHz
  111. {
  112.   unsigned long recivecod = 0; // kod odebrany z 433MHz
  113.   if (mySwitch.available()) {
  114.  
  115.     String ss = " * " + String(mySwitch.getReceivedValue()) + " - " + String(mySwitch.getReceivedDelay()) + " * " ;
  116.  
  117.   if(termesp){
  118.        BlynkvirtualWrite_str(29, ss);
  119.   }
  120.     recivecod = mySwitch.getReceivedValue();
  121.  
  122.     if (oldrecivecod != recivecod) { //zabezpieczenie przed wielkorotnym wysyłaniem do APP przy powtórzeniach kodu
  123.       oldrecivecod = recivecod;
  124.       if ( pirpompa == mySwitch.getReceivedValue()) pomparunpir();
  125.       if ( gateopen == mySwitch.getReceivedValue()) infgateopen();
  126.       if ( gateclose == mySwitch.getReceivedValue()) infgateclose();
  127.     }
  128.     mySwitch.resetAvailable();
  129.   }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement