/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * DESCRIPTION * * Simple binary switch example * Connect button or door/window reed switch between * digitial I/O pin 3 (BUTTON_PIN below) and GND. * http://www.mysensors.org/build/binary */ // Enable debug prints to serial monitor #define MY_DEBUG // Enable and select radio type attached #define MY_RADIO_RF24 //#define MY_RADIO_RFM69 #include #include #define NUMBER_OF_SWITCHES 2 Bounce debouncer[NUMBER_OF_SWITCHES]; int oldValue[NUMBER_OF_SWITCHES]; int switchPin[NUMBER_OF_SWITCHES] = {3,4}; //<<<<<<<<<<< set your switch pins here MyMessage msg(0,V_TRIPPED); void setup() { for (int i = 0; i < NUMBER_OF_SWITCHES; i++) { pinMode(switchPin[i],INPUT); digitalWrite(switchPin[i], HIGH); debouncer[i] = Bounce(); debouncer[i].attach(switchPin[i]); debouncer[i].interval(5); } } void presentation() { for (int i = 0; i < NUMBER_OF_SWITCHES; i++) { present(switchPin[i], S_DOOR); delay(250); } } // void loop() { for (int i = 0; i < NUMBER_OF_SWITCHES; i++) { debouncer[i].update(); int value = debouncer[i].read(); if (value != oldValue[i]) { send(msg.setSensor(switchPin[i]).set(value == HIGH? true : false)); } oldValue[i] = value; } }