Advertisement
Krzyspx

brama3,5klaw

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