Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Enable debug prints to serial monitor
- #define MY_DEBUG
- // Enable and select radio type attached
- //#define MY_RADIO_NRF24
- //#define MY_RADIO_RFM69
- // Enable serial gateway
- #define MY_GATEWAY_SERIAL
- // Enable inclusion mode
- #define MY_INCLUSION_MODE_FEATURE
- // Enable Inclusion mode button on gateway
- #define MY_INCLUSION_BUTTON_FEATURE
- // Inverses behavior of inclusion button (if using external pullup)
- //#define MY_INCLUSION_BUTTON_EXTERNAL_PULLUP
- // Set inclusion mode duration (in seconds)
- #define MY_INCLUSION_MODE_DURATION 60
- // Digital pin used for inclusion mode button
- //#define MY_RF24_CE_PIN 3
- //#define MY_RF24_CS_PIN 2
- #include <SPI.h>
- #include <MySensors.h>
- #include <Bounce2.h>
- #include <RCSwitch.h>
- #define NUMBER_OF_PLUGS 3 // Total number of attached plugs
- #define CODE_60On 5330227
- #define CODE_60Off 5330236
- #define CODE_61On 5330371
- #define CODE_61Off 5330380
- #define CODE_62On 5330691
- #define CODE_62Off 5330700
- RCSwitch mySwitch = RCSwitch();
- // Enable repeater functionality for this node
- #define MY_REPEATER_FEATURE
- //PRZEKAZNIKI ################################################################ PRZEKAŹNIKI
- #define RELAY_1 4 //przekaznik sypialnia
- #define RELAY_2 5 //przekaznik kotłownia
- #define RELAY_3 6 //przekaznik łazienka góra
- #define RELAY_4 7 //przekaznik pok Mai
- #define RELAY_5 8 //przekaznik pok Jasia
- #define RELAY_6 9 //przekaznik p n garazem
- #define RELAY_7 10 //przekaznik strych
- #define RELAY_8 11 //przekaźnik przedsionek
- #define RELAY_10 13 //przekaźnik kuchnia
- #define RELAY_19 22 //przekaźnik salonTV
- #define RELAY_20 23 //przekaźnik salon cegła
- #define RELAY_21 24 //przekaźnik salon jadalnia
- #define RELAY_22 25 //przekaźnik pokój mały
- #define RELAY_25 28 //przekaxnik przed garażem
- #define RELAY_26 29 //przekaźnik garaż
- #define RELAY_27 30 //garaż tablica
- #define RELAY_29 32 //przekaźnik za kotłownią
- #define RELAY_24 27 //przekaźnik przed domem
- #define RELAY_30 33 //przekaźnik tars
- // Arduino Digital I/O pin number for first relay (second on pin+1 etc)
- //#define NUMBER_OF_RELAYS 3 // Total number of attached relays
- #define RELAY_ON 0 // GPIO value to write to turn on attached relay
- #define RELAY_OFF 1 // GPIO value to write to turn off attached relay
- //PRZYCISKI ################################################################### PRZYCISKI
- #define BUTTON1_PIN A0 //sypialnia
- #define BUTTON2_PIN A1 //kotłownia
- #define BUTTON3_PIN A2 //łazienka góra
- #define BUTTON4_PIN A3 //pok Mai
- #define BUTTON5_PIN A4 //pok Jaśka
- #define BUTTON6_PIN A5 //pok nad garażem
- #define BUTTON7_PIN A6 //strych
- #define BUTTON8_PIN A7 //przedsionek
- #define BUTTON10_PIN A9 //kuchnia
- #define BUTTON19_PIN A10 //salonTV
- #define BUTTON20_PIN A11 //salon cegła
- #define BUTTON21_PIN A12 //salon jadalnia
- #define BUTTON22_PIN A13 //pokój mały
- #define BUTTON24_PIN A15 //przed domem
- #define BUTTON25_PIN 34 //światło przed garażem
- #define BUTTON26_PIN 35 //światło garaż
- #define BUTTON27_PIN 36 //światło garaż tablica
- #define BUTTON29_PIN 38 //światło za kotłownią
- #define BUTTON30_PIN 39 //światło taras
- //PIRy
- #define PIR1_PIN 44
- #define PIR2_PIN 45
- #define PIR3_PIN 46
- #define PIR4_PIN 47
- #define PIR5_PIN 48
- #define PIR6_PIN 49
- #define PIR7_PIN 50
- //pir przed domem #define PIR8_PIN 51
- //alarm
- #define UZBROJONY 52
- #define ALARM 53
- void before() {
- //pierwszy przycisk sypialnia pinMode(4 - pin przekaźnika loadstate(1) - numer przekaźnika czyli Lp.
- pinMode(4, OUTPUT); // ustawianie output pinów
- digitalWrite(4, loadState(1)?RELAY_ON:RELAY_OFF); //ustawia ostatni stan z EPROM
- pinMode(5, OUTPUT); //drugi przycisk - kotłownia
- digitalWrite(5, loadState(2)?RELAY_ON:RELAY_OFF);
- pinMode(6, OUTPUT);//trzeci przycisk - łazienka góra
- digitalWrite(6, loadState(3)?RELAY_ON:RELAY_OFF);
- pinMode(7, OUTPUT);//czwarty przycisk - pok Mai
- digitalWrite(7, loadState(4)?RELAY_ON:RELAY_OFF);
- pinMode(8, OUTPUT); //piąty przycisk - pok Jasia
- digitalWrite(8, loadState(5)?RELAY_ON:RELAY_OFF);
- pinMode(9, OUTPUT); //szósty przycisk - pok nad garażem
- digitalWrite(9, loadState(6)?RELAY_ON:RELAY_OFF);
- pinMode(10, OUTPUT); //siódmy przycisk - strych
- digitalWrite(10, loadState(7)?RELAY_ON:RELAY_OFF);
- pinMode(11, OUTPUT);//ósmy przycisk - przedsionek
- digitalWrite(11, loadState(8)?RELAY_ON:RELAY_OFF);
- pinMode(13, OUTPUT);//dziesiąty przycisk - kuchnia
- digitalWrite(13, loadState(10)?RELAY_ON:RELAY_OFF);
- pinMode(22, OUTPUT);//19 przycisk salonTV
- digitalWrite(22, loadState(19)?RELAY_ON:RELAY_OFF);
- pinMode(23, OUTPUT);//20 przycisk - salon cegła
- digitalWrite(23, loadState(20)?RELAY_ON:RELAY_OFF);
- pinMode(24, OUTPUT);//21 przycisk salon jadalnia
- digitalWrite(24, loadState(21)?RELAY_ON:RELAY_OFF);
- pinMode(25, OUTPUT);//22 przycisk pok mały
- digitalWrite(25, loadState(22)?RELAY_ON:RELAY_OFF);
- pinMode(27, OUTPUT);//dwudziesty czwarty przycisk przed domem
- digitalWrite(27, loadState(24)?RELAY_ON:RELAY_OFF);
- pinMode(28, OUTPUT);//25 przycisk przed garażem
- digitalWrite(28, loadState(25)?RELAY_ON:RELAY_OFF);
- pinMode(29, OUTPUT);//26 przycisk - garaż
- digitalWrite(29, loadState(26)?RELAY_ON:RELAY_OFF);
- pinMode(30, OUTPUT);//27 przycisk garaż tablica
- digitalWrite(30, loadState(27)?RELAY_ON:RELAY_OFF);
- pinMode(32, OUTPUT);//29 przycisk za kotłownią
- digitalWrite(32, loadState(29)?RELAY_ON:RELAY_OFF);
- pinMode(33, OUTPUT);//30 przycisk za taras
- digitalWrite(33, loadState(30)?RELAY_ON:RELAY_OFF);
- }
- // przycisków - debouncer zgodny z numerem przycisku
- Bounce debouncer = Bounce();
- Bounce debouncer2 = Bounce();
- Bounce debouncer3 = Bounce();
- Bounce debouncer4 = Bounce();
- Bounce debouncer5 = Bounce();
- Bounce debouncer6 = Bounce();
- Bounce debouncer7 = Bounce();
- Bounce debouncer8 = Bounce();
- Bounce debouncer10 = Bounce();
- Bounce debouncer19 = Bounce();
- Bounce debouncer20 = Bounce();
- Bounce debouncer21 = Bounce();
- Bounce debouncer22 = Bounce();
- Bounce debouncer24 = Bounce();
- Bounce debouncer25 = Bounce();
- Bounce debouncer26 = Bounce();
- Bounce debouncer27 = Bounce();
- Bounce debouncer29 = Bounce();
- Bounce debouncer30 = Bounce();
- // pirów
- Bounce debouncer44 = Bounce();
- Bounce debouncer45 = Bounce();
- Bounce debouncer46 = Bounce();
- Bounce debouncer47 = Bounce();
- Bounce debouncer48 = Bounce();
- Bounce debouncer49 = Bounce();
- Bounce debouncer50 = Bounce();
- // pir8 Bounce debouncer51= Bounce();
- Bounce debouncer52 = Bounce();
- Bounce debouncer53 = Bounce();
- //tylko dla pirów
- int oldValue44=-1;
- int oldValue45=-1;
- int oldValue46=-1;
- int oldValue47=-1;
- int oldValue48=-1;
- int oldValue49=-1;
- int oldValue50=-1;
- // int oldValue51=-1;
- int oldValue52=-1;
- int oldValue53=-1;
- MyMessage msg(1, V_LIGHT);//Swiatło sypialnia
- MyMessage msg2(2, V_LIGHT);//swiatło kotłownia
- MyMessage msg3(3, V_LIGHT);//swiatło łazienak góra
- MyMessage msg4(4, V_LIGHT);//swiatło pok Mai
- MyMessage msg5(5, V_LIGHT);//swiatło pok Jasia
- MyMessage msg6(6, V_LIGHT);//swiatło pok nad garażem
- MyMessage msg7(7, V_LIGHT);//swiatło strych
- MyMessage msg8(8, V_LIGHT);//swiatło przedsionek
- MyMessage msg10(10, V_LIGHT);//swiatło kuchnia
- MyMessage msg19(19, V_LIGHT);//salonTV
- MyMessage msg20(20, V_LIGHT);//salon cegła
- MyMessage msg21(21, V_LIGHT);//salon jadalnia
- MyMessage msg22(22, V_LIGHT);//pok mały
- MyMessage msg24(24, V_LIGHT);//swiatło przed domem
- MyMessage msg25(25, V_LIGHT);//przed garażem
- MyMessage msg26(26, V_LIGHT);//garaż
- MyMessage msg27(27, V_LIGHT);//garaż tablica
- MyMessage msg29(29, V_LIGHT);//za kotłownią
- MyMessage msg30(30, V_LIGHT);//taras
- //PIRY
- MyMessage msg44(44, V_TRIPPED);
- MyMessage msg45(45, V_TRIPPED);
- MyMessage msg46(46, V_TRIPPED);
- MyMessage msg47(47, V_TRIPPED);
- MyMessage msg48(48, V_TRIPPED);
- MyMessage msg49(49, V_TRIPPED);
- MyMessage msg50(50, V_TRIPPED);
- // tu bedzie PIR przed domem MyMessage msg51(51, V_TRIPPED);
- MyMessage msg52(52, V_LIGHT); //uzbrojony
- MyMessage msg53(53, V_LIGHT); //alarm
- void setup() {
- // Setup locally attached sensors
- mySwitch.enableTransmit(42);
- mySwitch.setRepeatTransmit(15);
- mySwitch.setPulseLength(206);
- // Setup locally attached sensors
- delay(10000);
- // ustawienia przycisków
- pinMode(BUTTON1_PIN, INPUT_PULLUP);
- pinMode(BUTTON2_PIN, INPUT_PULLUP);
- pinMode(BUTTON3_PIN, INPUT_PULLUP);
- pinMode(BUTTON4_PIN, INPUT_PULLUP);
- pinMode(BUTTON5_PIN, INPUT_PULLUP);
- pinMode(BUTTON6_PIN, INPUT_PULLUP);
- pinMode(BUTTON7_PIN, INPUT_PULLUP);
- pinMode(BUTTON8_PIN, INPUT_PULLUP);
- pinMode(BUTTON10_PIN, INPUT_PULLUP);
- pinMode(BUTTON19_PIN, INPUT_PULLUP);
- pinMode(BUTTON20_PIN, INPUT_PULLUP);
- pinMode(BUTTON21_PIN, INPUT_PULLUP);
- pinMode(BUTTON22_PIN, INPUT_PULLUP);
- pinMode(BUTTON24_PIN, INPUT_PULLUP);
- pinMode(BUTTON25_PIN, INPUT_PULLUP);
- pinMode(BUTTON26_PIN, INPUT_PULLUP);
- pinMode(BUTTON27_PIN, INPUT_PULLUP);
- pinMode(BUTTON29_PIN, INPUT_PULLUP);
- pinMode(BUTTON30_PIN, INPUT_PULLUP);
- //ustawienia pirów
- pinMode(PIR1_PIN, INPUT_PULLUP);
- pinMode(PIR2_PIN, INPUT_PULLUP);
- pinMode(PIR3_PIN, INPUT_PULLUP);
- pinMode(PIR4_PIN, INPUT_PULLUP);
- pinMode(PIR5_PIN, INPUT_PULLUP);
- pinMode(PIR6_PIN, INPUT_PULLUP);
- pinMode(PIR7_PIN, INPUT_PULLUP);
- // PIR8 pinMode(PIR8_PIN, INPUT_PULLUP);
- pinMode(UZBROJONY, INPUT_PULLUP);
- pinMode(ALARM, INPUT_PULLUP);
- // DEBOUNCERY ########################################################################## DEBOUNCERY
- // przyciski
- debouncer.attach(BUTTON1_PIN);
- debouncer.interval(5);
- debouncer2.attach(BUTTON2_PIN);
- debouncer2.interval(5);
- debouncer3.attach(BUTTON3_PIN);
- debouncer3.interval(5);
- debouncer4.attach(BUTTON4_PIN);
- debouncer4.interval(5);
- debouncer5.attach(BUTTON5_PIN);
- debouncer5.interval(5);
- debouncer6.attach(BUTTON6_PIN);
- debouncer6.interval(5);
- debouncer7.attach(BUTTON7_PIN);
- debouncer7.interval(5);
- debouncer8.attach(BUTTON8_PIN);
- debouncer8.interval(5);
- debouncer10.attach(BUTTON10_PIN);
- debouncer10.interval(5);
- debouncer19.attach(BUTTON19_PIN);
- debouncer19.interval(5);
- debouncer20.attach(BUTTON20_PIN);
- debouncer20.interval(5);
- debouncer21.attach(BUTTON21_PIN);
- debouncer21.interval(5);
- debouncer22.attach(BUTTON22_PIN);
- debouncer22.interval(5);
- debouncer24.attach(BUTTON24_PIN);
- debouncer24.interval(5);
- debouncer25.attach(BUTTON25_PIN);
- debouncer25.interval(5);
- debouncer26.attach(BUTTON26_PIN);
- debouncer26.interval(5);
- debouncer27.attach(BUTTON27_PIN);
- debouncer27.interval(5);
- debouncer29.attach(BUTTON29_PIN);
- debouncer29.interval(5);
- debouncer30.attach(BUTTON30_PIN);
- debouncer30.interval(5);
- //piry
- debouncer44.attach(PIR1_PIN);
- debouncer44.interval(5);
- debouncer45.attach(PIR2_PIN);
- debouncer45.interval(5);
- debouncer46.attach(PIR3_PIN);
- debouncer46.interval(5);
- debouncer47.attach(PIR4_PIN);
- debouncer47.interval(5);
- debouncer48.attach(PIR5_PIN);
- debouncer48.interval(5);
- debouncer49.attach(PIR6_PIN);
- debouncer49.interval(5);
- debouncer50.attach(PIR7_PIN);
- debouncer50.interval(5);
- // debouncer51.attach(PIR7_PIN);
- // debouncer51.interval(5);
- debouncer52.attach(UZBROJONY);
- debouncer52.interval(5);
- debouncer53.attach(ALARM);
- debouncer53.interval(5);
- //presentation();
- }
- void presentation()
- {
- //############################################################################################### PRESENT
- // wysyła wersję skrecha do kontrolera
- sendSketchInfo("Arduino-Mega-Kuba", "v5");
- present(1, S_LIGHT);
- present(2, S_LIGHT);
- present(3, S_LIGHT);
- present(4, S_LIGHT);
- present(5, S_LIGHT);
- present(6, S_LIGHT);
- present(7, S_LIGHT);
- present(8, S_LIGHT);
- present(10, S_LIGHT);
- present(19, S_LIGHT);
- present(20, S_LIGHT);
- present(21, S_LIGHT);
- present(22, S_LIGHT);
- present(24, S_LIGHT);
- present(25, S_LIGHT);
- present(26, S_LIGHT);
- present(27, S_LIGHT);
- present(29, S_LIGHT);
- present(30, S_LIGHT);
- present(44, S_MOTION);
- present(45, S_MOTION);
- present(46, S_MOTION);
- present(47, S_MOTION);
- present(48, S_MOTION);
- present(49, S_MOTION);
- present(50, S_MOTION);
- // bedzie pokazywalo pir8 present(51, S_MOTION);
- present(52, S_LIGHT);
- present(53, S_LIGHT);
- present(60, S_LIGHT);
- present(61, S_LIGHT);
- present(62, S_LIGHT);
- }
- //################################################################################################## LOOP
- void loop() {
- // Send locally attached sensor data here
- //przekaźnik1 - sypialnia debouncer
- if (debouncer.update()) {
- // Get the update value.
- int value = debouncer.read();
- // Send in the new value.
- if(value == LOW){
- saveState(1, !loadState(1));
- digitalWrite(RELAY_1, loadState(1)?RELAY_ON:RELAY_OFF);
- send(msg.set(loadState(1)));
- }}
- //przekaznik kotłownia debouncer2
- if (debouncer2.update()) {
- // Get the update value.
- int value2 = debouncer2.read();
- // Send in the new value.
- if(value2 == LOW){
- saveState(2, !loadState(2));
- digitalWrite(RELAY_2, loadState(2)?RELAY_ON:RELAY_OFF);
- send(msg2.set(loadState(2)));
- }}
- //przekaznik łazienka góra debouncer3
- if (debouncer3.update()) {
- // Get the update value.
- int value3 = debouncer3.read();
- // Send in the new value.
- if(value3 == LOW){
- saveState(3, !loadState(3));
- digitalWrite(RELAY_3, loadState(3)?RELAY_ON:RELAY_OFF);
- send(msg3.set(loadState(3)));
- }}
- //przekaznik pok Mai debouncer4
- if (debouncer4.update()) {
- // Get the update value.
- int value4 = debouncer4.read();
- // Send in the new value.
- if(value4 == LOW){
- saveState(4, !loadState(4));
- digitalWrite(RELAY_4, loadState(4)?RELAY_ON:RELAY_OFF);
- send(msg4.set(loadState(4)));
- }}
- //przekaznik pok Jasia debouncer5
- if (debouncer5.update()) {
- // Get the update value.
- int value5 = debouncer5.read();
- // Send in the new value.
- if(value5 == LOW){
- saveState(5, !loadState(5));
- digitalWrite(RELAY_5, loadState(5)?RELAY_ON:RELAY_OFF);
- send(msg5.set(loadState(5)));
- }}
- //przekaznik pok nad garażem debouncer6
- if (debouncer6.update()) {
- // Get the update value.
- int value6 = debouncer6.read();
- // Send in the new value.
- if(value6 == LOW){
- saveState(6, !loadState(6));
- digitalWrite(RELAY_6, loadState(6)?RELAY_ON:RELAY_OFF);
- send(msg6.set(loadState(6)));
- }}
- //przekaznik strych debouncer7
- if (debouncer7.update()) {
- // Get the update value.
- int value7 = debouncer7.read();
- // Send in the new value.
- if(value7 == LOW){
- saveState(7, !loadState(7));
- digitalWrite(RELAY_7, loadState(7)?RELAY_ON:RELAY_OFF);
- send(msg7.set(loadState(7)));
- }}
- //przekaznik przedsionek debouncer8, relay state i msg zgodne z debouncerem
- if (debouncer8.update()) {
- // Get the update value.
- int value8 = debouncer8.read();
- // Send in the new value.
- if(value8 == LOW){
- saveState(8, !loadState(8));
- digitalWrite(RELAY_8, loadState(8)?RELAY_ON:RELAY_OFF);
- send(msg8.set(loadState(8)));
- }}
- //przekaznik kuchnia debouncer10, relay state i msg zgodne z debouncerem
- if (debouncer10.update()) {
- // Get the update value.
- int value10 = debouncer10.read();
- // Send in the new value.
- if(value10 == LOW){
- saveState(10, !loadState(10));
- digitalWrite(RELAY_10, loadState(10)?RELAY_ON:RELAY_OFF);
- send(msg10.set(loadState(10)));
- }}
- //przekaznik salonTV debouncer19, relay state i msg zgodne z debouncerem
- if (debouncer19.update()) {
- // Get the update value.
- int value19 = debouncer19.read();
- // Send in the new value.
- if(value19 == LOW){
- saveState(19, !loadState(19));
- digitalWrite(RELAY_19, loadState(19)?RELAY_ON:RELAY_OFF);
- send(msg19.set(loadState(19)));
- }}
- //przekaznik salon cegła debouncer20, value relay state i msg zgodne z debouncerem
- if (debouncer20.update()) {
- // Get the update value.
- int value20 = debouncer20.read();
- // Send in the new value.
- if(value20 == LOW){
- saveState(20, !loadState(20));
- digitalWrite(RELAY_20, loadState(20)?RELAY_ON:RELAY_OFF);
- send(msg20.set(loadState(20)));
- }}
- //przekaznik salon jadalnia debouncer21, value relay state i msg zgodne z debouncerem
- if (debouncer21.update()) {
- // Get the update value.
- int value21 = debouncer21.read();
- // Send in the new value.
- if(value21 == LOW){
- saveState(21, !loadState(21));
- digitalWrite(RELAY_21, loadState(21)?RELAY_ON:RELAY_OFF);
- send(msg21.set(loadState(21)));
- }}
- //przekaznik mały pokój debouncer22, value relay state i msg zgodne z debouncerem
- if (debouncer22.update()) {
- // Get the update value.
- int value22 = debouncer22.read();
- // Send in the new value.
- if(value22 == LOW){
- saveState(22, !loadState(22));
- digitalWrite(RELAY_22, loadState(22)?RELAY_ON:RELAY_OFF);
- send(msg22.set(loadState(22)));
- }}
- //przekaznik przed domem debouncer24, value relay state i msg zgodne z debouncerem
- if (debouncer24.update()) {
- // Get the update value.
- int value24 = debouncer24.read();
- // Send in the new value.
- if(value24 == LOW){
- saveState(24, !loadState(24));
- digitalWrite(RELAY_24, loadState(24)?RELAY_ON:RELAY_OFF);
- send(msg24.set(loadState(24)));
- }}
- //przekaznik przed garażem debouncer25, value relay state i msg zgodne z debouncerem
- if (debouncer25.update()) {
- // Get the update value.
- int value25 = debouncer25.read();
- // Send in the new value.
- if(value25 == LOW){
- saveState(25, !loadState(25));
- digitalWrite(RELAY_25, loadState(25)?RELAY_ON:RELAY_OFF);
- send(msg25.set(loadState(25)));
- }}
- //przekaznik garaż debouncer26, value relay state i msg zgodne z debouncerem
- if (debouncer26.update()) {
- // Get the update value.
- int value26 = debouncer26.read();
- // Send in the new value.
- if(value26 == LOW){
- saveState(26, !loadState(26));
- digitalWrite(RELAY_26, loadState(26)?RELAY_ON:RELAY_OFF);
- send(msg26.set(loadState(26)));
- }}
- //przekaznik garaż tablica debouncer27, value relay state i msg zgodne z debouncerem
- if (debouncer27.update()) {
- // Get the update value.
- int value27 = debouncer27.read();
- // Send in the new value.
- if(value27 == LOW){
- saveState(27, !loadState(27));
- digitalWrite(RELAY_27, loadState(27)?RELAY_ON:RELAY_OFF);
- send(msg27.set(loadState(27)));
- }}
- //przekaznik za kotłownią debouncer29, value relay state i msg zgodne z debouncerem
- if (debouncer29.update()) {
- // Get the update value.
- int value29 = debouncer29.read();
- // Send in the new value.
- if(value29 == LOW){
- saveState(29, !loadState(29));
- digitalWrite(RELAY_29, loadState(29)?RELAY_ON:RELAY_OFF);
- send(msg29.set(loadState(29)));
- }}
- //przekaznik taras debouncer30, value relay state i msg zgodne z debouncerem
- if (debouncer30.update()) {
- // Get the update value.
- int value30 = debouncer30.read();
- // Send in the new value.
- if(value30 == LOW){
- saveState(30, !loadState(30));
- digitalWrite(RELAY_30, loadState(30)?RELAY_ON:RELAY_OFF);
- send(msg30.set(loadState(30)));
- }}
- //1pir przedsionek
- if (debouncer44.update());{
- // Get the update value
- int value44 = debouncer44.read();
- if (value44 != oldValue44) {
- // Send in the new value
- send(msg44.set(value44==LOW ? 1 : 0));
- oldValue44 = value44;
- }}
- //2pir góra
- if (debouncer45.update());{
- // Get the update value
- int value45 = debouncer45.read();
- if (value45 != oldValue45) {
- // Send in the new value
- send(msg45.set(value45==LOW ? 1 : 0));
- oldValue45 = value45;
- }}
- //3pir kuchnia
- if (debouncer46.update());{
- // Get the update value
- int value46 = debouncer46.read();
- if (value46 != oldValue46) {
- // Send in the new value
- send(msg46.set(value46==LOW ? 1 : 0));
- oldValue46 = value46;
- }}
- //4pir salon
- if (debouncer47.update());{
- // Get the update value
- int value47 = debouncer47.read();
- if (value47 != oldValue47) {
- // Send in the new value
- send(msg47.set(value47==LOW ? 1 : 0));
- oldValue47 = value47;
- }
- }
- //5pir garaż
- if (debouncer48.update());{
- // Get the update value
- int value48 = debouncer48.read();
- if (value48 != oldValue48) {
- // Send in the new value
- send(msg48.set(value48==LOW ? 1 : 0));
- oldValue48 = value48;
- }}
- //6pir pokój mały
- if (debouncer49.update());{
- // Get the update value
- int value49 = debouncer49.read();
- if (value49 != oldValue49) {
- // Send in the new value
- send(msg49.set(value49==LOW ? 1 : 0));
- oldValue49 = value49;
- }}
- //7pir kotłownia
- if (debouncer50.update());{
- // Get the update value
- int value50 = debouncer50.read();
- if (value50 != oldValue50) {
- // Send in the new value
- send(msg50.set(value50==LOW ? 1 : 0));
- oldValue50 = value50;
- }}
- //8pir przed domem
- // if (debouncer51.update());{
- // Get the update value
- // int value51 = debouncer51.read();
- // if (value51 != oldValue51) {
- // Send in the new value
- // send(msg51.set(value51==LOW ? 1 : 0));
- // oldValue51 = value51;
- // }}
- //alarm uzbrojony
- if (debouncer52.update());{
- // Get the update value
- int value52 = debouncer52.read();
- if (value52 != oldValue52) {
- // Send in the new value
- send(msg52.set(value52==LOW ? 1 : 0));
- oldValue52 = value52;
- }}
- //alarm!!!
- if (debouncer53.update());{
- // Get the update value
- int value53 = debouncer53.read();
- if (value53 != oldValue53) {
- // Send in the new value
- send(msg53.set(value53==LOW ? 1 : 0));
- oldValue53 = value53;
- }}
- }
- void receive(const MyMessage &message) {
- // We only expect one type of message from controller. But we better check anyway.
- if (message.type==V_LIGHT) {
- // Change relay state
- digitalWrite(message.sensor-1+RELAY_1, message.getBool()?RELAY_ON:RELAY_OFF);
- // Store state in eeprom
- saveState(message.sensor, message.getBool());
- // Write some debug info
- Serial.print("Incoming change for sensor:");
- Serial.print(message.sensor);
- Serial.print(", New status: ");
- Serial.println(message.getBool());
- int incomingLightState = message.getBool();
- int incomingOutlet = message.sensor;
- if (incomingOutlet==60) {
- if (incomingLightState==1) {
- // Turn on socket 1
- Serial.println("Turn on Socket 1");
- mySwitch.send(CODE_60On, 24); // These codes are unique to each outlet
- delay(50);
- }
- if (incomingLightState==0) {
- // Turn off socket 1
- Serial.println("Turn off Socket 1");
- mySwitch.send(CODE_60Off, 24);
- delay(50);
- }
- }
- if (incomingOutlet==61) {
- if (incomingLightState==1) {
- // Turn on socket 2
- Serial.println("Turn on Socket 2");
- mySwitch.send(CODE_61On, 24);
- delay(50);
- }
- if (incomingLightState==0) {
- // Turn off socket 2
- Serial.println("Turn off Socket 2");
- mySwitch.send(CODE_61Off, 24);
- delay(50);
- }
- }
- if (incomingOutlet==62) {
- if (incomingLightState==1) {
- // Turn on socket 3
- Serial.println("Turn on Socket 3");
- mySwitch.send(CODE_62On, 24);
- delay(50);
- }
- if (incomingLightState==0) {
- // Turn off socket 3
- Serial.println("Turn off Socket 3");
- mySwitch.send(CODE_62Off, 24);
- delay(50);
- }
- }
- }
- delay(50);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement