Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Enable debug prints to serial monitor
- #define MY_DEBUG
- // Enable serial gateway
- #define MY_GATEWAY_SERIAL
- // Define a lower baud rate for Arduino's running on 8 MHz (Arduino Pro Mini 3.3V & SenseBender)
- #if F_CPU == 8000000L
- #define MY_BAUD_RATE 38400
- #endif
- // Enable inclusion mode
- #define MY_INCLUSION_MODE_FEATURE
- // Enable Inclusion mode button on gateway
- #define MY_INCLUSION_BUTTON_FEATURE
- // Set inclusion mode duration (in seconds)
- #define MY_INCLUSION_MODE_DURATION 60
- // Digital pin used for inclusion mode button
- #define MY_INCLUSION_MODE_BUTTON_PIN 3
- #include <SPI.h>
- #include <MySensors.h>
- #include <Bounce2.h>
- // Enable repeater functionality for this node
- #define MY_REPEATER_FEATURE
- #define Kontaktron1_CHILD_ID 30
- #define Kontaktron1_BUTTON_PIN 6 // Brama Garażowa Kontatktron
- unsigned long SLEEP_TIME = 1000; // Czas reakcji czujnika
- #define CzujnikRuchu1 7 // WC Pin podlaczenia czujnika PIR
- #define Czujnik1_CHILD_ID 45 // Id of the sensor child
- #define CzujnikRuchu2 8 // WC Pin podlaczenia czujnika PIR
- #define Czujnik2_CHILD_ID 46 // Id of the sensor child
- Bounce debouncer = Bounce();
- int oldValue=-1;
- // Change to V_LIGHT if you use S_LIGHT in presentation below
- MyMessage msg(Kontaktron1_CHILD_ID,V_TRIPPED);
- // Initialize motion message
- MyMessage msg15(Czujnik1_CHILD_ID, V_TRIPPED);
- MyMessage msg16(Czujnik2_CHILD_ID, V_TRIPPED);
- void setup()
- {
- // Setup the button
- pinMode(Kontaktron1_BUTTON_PIN,INPUT);
- // Activate internal pull-up
- digitalWrite(Kontaktron1_BUTTON_PIN,HIGH);
- pinMode(CzujnikRuchu1, INPUT); // sets the motion sensor digital pin as input
- pinMode(CzujnikRuchu2, INPUT);
- }
- void presentation() {
- // Register binary input sensor to gw (they will be created as child devices)
- // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
- // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
- present(Kontaktron1_CHILD_ID, S_DOOR);
- // Send the sketch version information to the gateway and Controller
- sendSketchInfo("Motion Sensor", "1.0");
- // Register all sensors to gw (they will be created as child devices)
- present(Czujnik1_CHILD_ID, S_MOTION);
- present(Czujnik2_CHILD_ID, S_MOTION);
- }
- // Check if digital input has changed and send in new value
- void loop()
- {
- uint8_t value;
- static uint8_t sentValue2=2;
- // Short delay to allow buttons to properly settle
- value = digitalRead(Kontaktron1_BUTTON_PIN);
- if (value != sentValue2) {
- // Value has changed from last transmission, send the updated value
- send(msg.set(value==HIGH ? 1 : 0));
- sentValue2 = value;
- }
- {
- // Read digital motion value
- boolean tripped = digitalRead(CzujnikRuchu1) == HIGH;
- Serial.println(tripped);
- send(msg15.set(tripped?"1":"0")); // Send tripped value to gw
- // Sleep until interrupt comes in on motion sensor. Send update every two minute.
- sleep(digitalPinToInterrupt(CzujnikRuchu1), CHANGE, SLEEP_TIME);
- }
- {
- // Read digital motion value
- boolean tripped = digitalRead(CzujnikRuchu2) == HIGH;
- Serial.println(tripped);
- send(msg16.set(tripped?"1":"0")); // Send tripped value to gw
- // Sleep until interrupt comes in on motion sensor. Send update every two minute.
- sleep(digitalPinToInterrupt(CzujnikRuchu2), CHANGE, SLEEP_TIME);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement