Advertisement
Guest User

domoticz

a guest
Sep 2nd, 2017
413
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.48 KB | None | 0 0
  1.  
  2. // Enable debug prints to serial monitor
  3. #define MY_DEBUG
  4.  
  5.  
  6.  
  7.  
  8. // Enable serial gateway
  9. #define MY_GATEWAY_SERIAL
  10.  
  11. // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
  12. #if F_CPU == 8000000L
  13. #define MY_BAUD_RATE 38400
  14. #endif
  15.  
  16.  
  17.  
  18. // Enable inclusion mode
  19. #define MY_INCLUSION_MODE_FEATURE
  20. // Enable Inclusion mode button on gateway
  21. #define MY_INCLUSION_BUTTON_FEATURE
  22.  
  23.  
  24.  
  25. // Set inclusion mode duration (in seconds)
  26. #define MY_INCLUSION_MODE_DURATION 60
  27. // Digital pin used for inclusion mode button
  28. #define MY_INCLUSION_MODE_BUTTON_PIN 3
  29.  
  30.  
  31.  
  32. #include <SPI.h>
  33. #include <MySensors.h>
  34. #include <Bounce2.h>
  35.  
  36. // Enable repeater functionality for this node
  37. #define MY_REPEATER_FEATURE
  38. #define Kontaktron1_CHILD_ID 30
  39. #define Kontaktron1_BUTTON_PIN 6 // Brama Garażowa Kontatktron
  40.  
  41.  
  42.  
  43. unsigned long SLEEP_TIME = 1000; // Czas reakcji czujnika
  44. #define CzujnikRuchu1 7 // WC Pin podlaczenia czujnika PIR
  45. #define Czujnik1_CHILD_ID 45 // Id of the sensor child
  46. #define CzujnikRuchu2 8 // WC Pin podlaczenia czujnika PIR
  47. #define Czujnik2_CHILD_ID 46 // Id of the sensor child
  48.  
  49.  
  50. Bounce debouncer = Bounce();
  51. int oldValue=-1;
  52.  
  53. // Change to V_LIGHT if you use S_LIGHT in presentation below
  54. MyMessage msg(Kontaktron1_CHILD_ID,V_TRIPPED);
  55.  
  56.  
  57. // Initialize motion message
  58. MyMessage msg15(Czujnik1_CHILD_ID, V_TRIPPED);
  59. MyMessage msg16(Czujnik2_CHILD_ID, V_TRIPPED);
  60.  
  61. void setup()
  62. {
  63. // Setup the button
  64. pinMode(Kontaktron1_BUTTON_PIN,INPUT);
  65.  
  66. // Activate internal pull-up
  67. digitalWrite(Kontaktron1_BUTTON_PIN,HIGH);
  68.  
  69.  
  70. pinMode(CzujnikRuchu1, INPUT); // sets the motion sensor digital pin as input
  71. pinMode(CzujnikRuchu2, INPUT);
  72. }
  73.  
  74. void presentation() {
  75. // Register binary input sensor to gw (they will be created as child devices)
  76. // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
  77. // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
  78. present(Kontaktron1_CHILD_ID, S_DOOR);
  79.  
  80.  
  81.  
  82. // Send the sketch version information to the gateway and Controller
  83. sendSketchInfo("Motion Sensor", "1.0");
  84.  
  85. // Register all sensors to gw (they will be created as child devices)
  86. present(Czujnik1_CHILD_ID, S_MOTION);
  87. present(Czujnik2_CHILD_ID, S_MOTION);
  88. }
  89.  
  90. // Check if digital input has changed and send in new value
  91. void loop()
  92. {
  93. uint8_t value;
  94. static uint8_t sentValue2=2;
  95.  
  96. // Short delay to allow buttons to properly settle
  97.  
  98. value = digitalRead(Kontaktron1_BUTTON_PIN);
  99.  
  100. if (value != sentValue2) {
  101. // Value has changed from last transmission, send the updated value
  102. send(msg.set(value==HIGH ? 1 : 0));
  103. sentValue2 = value;
  104. }
  105.  
  106.  
  107.  
  108.  
  109.  
  110. {
  111. // Read digital motion value
  112. boolean tripped = digitalRead(CzujnikRuchu1) == HIGH;
  113.  
  114. Serial.println(tripped);
  115. send(msg15.set(tripped?"1":"0")); // Send tripped value to gw
  116.  
  117. // Sleep until interrupt comes in on motion sensor. Send update every two minute.
  118. sleep(digitalPinToInterrupt(CzujnikRuchu1), CHANGE, SLEEP_TIME);
  119. }
  120. {
  121. // Read digital motion value
  122. boolean tripped = digitalRead(CzujnikRuchu2) == HIGH;
  123.  
  124. Serial.println(tripped);
  125. send(msg16.set(tripped?"1":"0")); // Send tripped value to gw
  126.  
  127. // Sleep until interrupt comes in on motion sensor. Send update every two minute.
  128. sleep(digitalPinToInterrupt(CzujnikRuchu2), CHANGE, SLEEP_TIME);
  129. }
  130. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement