Help!!! Binary & Relay Compilation Not Working
-
This is the serial message I get
repeater started, id 12
send: 12-12-0-0 s=255,c=0,t=18,pt=0,l=5,st=ok:1.4.1
send: 12-12-0-0 s=255,c=3,t=6,pt=1,l=1,st=ok:0
read: 0-0-12 s=255,c=3,t=6,pt=0,l=1:M
send: 12-12-0-0 s=255,c=3,t=11,pt=0,l=5,st=ok:Relay
send: 12-12-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 12-12-0-0 s=255,c=3,t=11,pt=0,l=12,st=ok:Alarm Pannel
send: 12-12-0-0 s=255,c=3,t=12,pt=0,l=3,st=ok:1.0
send: 12-12-0-0 s=255,c=3,t=1,pt=0,l=3,st=ok:1.0
send: 12-12-0-0 s=0,c=0,t=0,pt=0,l=5,st=ok:1.4.1
setup for switch: 5 complete
send: 12-12-0-0 s=1,c=0,t=3,pt=0,l=5,st=ok:1.4.1
read: 0-0-12 s=255,c=3,t=1,pt=0,l=10:1435918408 -
fyi, just pick one name...
gw.sendSketchInfo("Relay", "1.0");
gw.sendSketchInfo("Alarm Pannel", "1.0");What is this supposed to be doing? it looks like:
reporting the state of three reed switches
actuating a relayWhy are you using the dalays? time?
hard to really understand what you are trying to do here...
-
@BulldogLowell
Essentially, I will like to combine Array Binary and Relay Actuator in one sketch. -
three binary switches and a single relay?
-
Any ideas how I can get this to work?
-
Any ideas how I can get this to work?
@jeylites it looks like you are overwriting i somewhere inside the loop. can you try to add prints of the value of i at several strategic points to see when it becomes 5? I would suggest to add one (and also print BUTTON_PIN[i]) before "msg[i].sensor = i;", one after "// Setup the button" and print i with the BUTTON_PIN[i].
-
I'm going to try fix it as suggested. But the thing is it complies....
-
I'm going to try fix it as suggested. But the thing is it complies....
@jeylites Alas compiling is not a guarantee against memory overwrites....as button_pin should have shown 4 and not 5 i assume that either the index (i) got corrupt or the button_pin array.
-
Any ideas how I can get this to work?
I think this is what you want. I cannot test it right now, but it does compile:
#include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #define NUMBER_OF_REEDS 3 const int relayPin = 3; const int reedPin[NUMBER_OF_REEDS] = {4, 5, 6}; int reedState[NUMBER_OF_REEDS]; Bounce debouncer[NUMBER_OF_REEDS] = Bounce(); MySensor gw; MyMessage msg[NUMBER_OF_REEDS]; void setup() { gw.begin(incomingMessage, AUTO, true); gw.sendSketchInfo("Test", "1.0a"); gw.present(0, S_LIGHT); pinMode(relayPin, OUTPUT); digitalWrite(relayPin, gw.loadState(0)); for (int i = 0; i < NUMBER_OF_REEDS; i++) { debouncer[i].attach(reedPin[i]); debouncer[i].interval(5); pinMode(reedPin[i], INPUT_PULLUP); gw.present(i, S_DOOR); gw.wait(250); } } void loop() { gw.process(); for (int i = 0; i < NUMBER_OF_REEDS; i++) { debouncer[i].update(); int value = debouncer[i].read(); if (value != reedState[i]) { gw.send(msg[i+1].set(value), false); // device number mismatch here because of the array reedState[i] = value; Serial.print("updating state for switch: "); Serial.print(reedPin[i]); Serial.print(" state: "); Serial.println(reedState[i]); } } } void incomingMessage(const MyMessage &message) { if (message.type == V_LIGHT) { int newState = message.getBool(); digitalWrite(relayPin, newState); gw.saveState(0, newState); Serial.print(F("Incoming change for relay, New state: ")); Serial.println(newState); } }EDIT: Updated to correct debounce class errors
-
to turn relay off automatically after two minutes (and send the updated "off status" to controller... try something like this untested code:
#include <MySensor.h> #include <SPI.h> #include <Bounce2.h> #define NUMBER_OF_REEDS 3 const int relayPin = 3; const int reedPin[NUMBER_OF_REEDS] = {4, 5, 6}; int reedState[NUMBER_OF_REEDS]; Bounce debouncer[NUMBER_OF_REEDS] = Bounce(); unsigned long relayTimer; MySensor gw; MyMessage msg[NUMBER_OF_REEDS]; MyMessage relayMessage(0,V_LIGHT); void setup() { gw.begin(incomingMessage, AUTO, true); gw.sendSketchInfo("Test", "1.0a"); gw.present(0, S_LIGHT); pinMode(relayPin, OUTPUT); digitalWrite(relayPin, gw.loadState(0)); for (int i = 0; i < NUMBER_OF_REEDS; i++) { debouncer[i].attach(reedPin[i]); debouncer[i].interval(5); pinMode(reedPin[i], INPUT_PULLUP); gw.present(i, S_DOOR); gw.wait(250); } } void loop() { gw.process(); for (int i = 0; i < NUMBER_OF_REEDS; i++) { debouncer[i].update(); int value = debouncer[i].read(); if (value != reedState[i]) { gw.send(msg[i+1].set(value), false); // device number mismatch here because of the array reedState[i] = value; Serial.print("updating state for switch: "); Serial.print(reedPin[i]); Serial.print(" state: "); Serial.println(reedState[i]); } } if (millis() - relayTimer > 2 * 60 * 1000UL && digitalRead(relayPin)) // two minute timer { digitalWrite(relayPin, LOW); gw.saveState(0, false); gw.send(relayMessage.set(false), true); } } void incomingMessage(const MyMessage &message) { if (message.type == V_LIGHT) { int newState = message.getBool(); digitalWrite(relayPin, newState); gw.saveState(0, newState); if (newState) { relayTimer = millis(); } Serial.print(F("Incoming change for relay, New state: ")); Serial.println(newState); } }
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login