help about simple roller shutter sketch
-
hi
i use this sketch for roller shutter with button.
i want when connection is fail so button work lonely ! and when push button if connection is ok a message send to controller and in domoticz i see open or close or stop.if connection is fail (or not) after 2 hours send a message to controller from state of Blind.#define MY_DEBUG #define MY_RADIO_NRF24 #define MY_RF24_CHANNEL 0 #define MY_REPEATER_FEATURE #define MY_NODE_ID 11 #define MY_TRANSPORT_WAIT_READY_MS 10000 #include <SPI.h> #include <MySensors.h> #include <Bounce2.h> #define RELAY_ON 0 #define RELAY_OFF 1 #define CHILD_ID 1 const int buttonPinA = 14; const int buttonPinB = 15; const int buttonPinC = 16; const int relayPinA = 3; const int relayPinB = 4; int oldValueA = 0; int oldValueB = 0; int oldValueC = 0; bool stateA = false; bool stateB = false; bool stateC = false; int trigger = 0; unsigned long time_m; unsigned long a; Bounce debouncerA = Bounce(); Bounce debouncerB = Bounce(); Bounce debouncerC = Bounce(); MyMessage msg(CHILD_ID, V_PERCENTAGE); void setup() { pinMode(buttonPinA, INPUT_PULLUP); pinMode(buttonPinB, INPUT_PULLUP); pinMode(buttonPinC, INPUT_PULLUP); pinMode(relayPinA, OUTPUT); pinMode(relayPinB, OUTPUT); debouncerA.attach(buttonPinA); debouncerA.interval(5); debouncerB.attach(buttonPinB); debouncerB.interval(5); debouncerC.attach(buttonPinC); debouncerC.interval(5); digitalWrite(relayPinA, RELAY_OFF); digitalWrite(relayPinB, RELAY_OFF); oldValueA = digitalRead(buttonPinA); oldValueB = digitalRead(buttonPinB); oldValueC = digitalRead(buttonPinC); } void presentation() { sendSketchInfo("Roller shutter", "1.0"); present(CHILD_ID, S_COVER); } void loop() { { time_m = millis(); a = time_m % 7200000; if (a == 0) { send(msg.set(stateA)); send(msg.set(stateB)); send(msg.set(stateC)); } } { debouncerA.update(); // Get the update value int valueA = debouncerA.read(); if (valueA != oldValueA) { stateA = !stateA; send(msg.set(stateA),false); digitalWrite(relayPinA, HIGH); delay(500); digitalWrite(relayPinB, LOW); oldValueA = valueA; } debouncerB.update(); // Get the update value int valueB = debouncerB.read(); if (valueB != oldValueB) { stateB = !stateB; send(msg.set(stateB),false); digitalWrite(relayPinA, HIGH); delay(500); digitalWrite(relayPinB, HIGH); oldValueB = valueB; } debouncerC.update(); // Get the update value int valueC = debouncerC.read(); if (valueC != oldValueC) { stateC = !stateC; send(msg.set(stateC),false); digitalWrite(relayPinB, HIGH); delay(500); digitalWrite(relayPinA, LOW); oldValueC = valueC; } } } void receive(const MyMessage &message) { // We only expect one type of message from controller. But we better check anyway. if (message.type == V_UP) { stateA = message.getBool(); digitalWrite(relayPinA, HIGH); delay(500); digitalWrite(relayPinB, LOW); } if (message.type == V_STOP ){ stateB = message.getBool(); digitalWrite(relayPinA, HIGH); delay(500); digitalWrite(relayPinB, HIGH); } if (message.type == V_DOWN){ stateC = message.getBool(); digitalWrite(relayPinB, HIGH); delay(500); digitalWrite(relayPinA, LOW); } // Write some debug info Serial.print("Incoming change for sensor:"); Serial.println(message.sensor); Serial.print("from node:"); Serial.println(message.sender); Serial.print(", New status: "); Serial.println(message.getBool()); }
what do change in my sketch ? thank you