Help with sleeping door sensor
-
Hi friend i need help with my code of sleeping door sensor.
i need add sending actual status of digital input and battery level and send this info each 7 seconds to GW.
#define MY_DEBUG #define MY_RADIO_NRF24 uint8_t NodeID = 88; #define MY_NODE_ID NodeID #define MY_PARENT_NODE_ID 0 uint8_t RF24_Channel = 30; #define MY_RF24_CHANNEL RF24_Channel #define LED_PIN 17 #define PRIMARY_BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch #define SECONDARY_BUTTON_PIN 2 // Arduino Digital I/O pin for button/reed switch unsigned long SLEEP_TIME = 7000; // Sleep time between tX #include <MySensors.h> #define SKETCH_NAME "Door RF Sensor" #define SKETCH_MAJOR_VER "1" #define SKETCH_MINOR_VER "1" #define PRIMARY_CHILD_ID 1 #define SECONDARY_CHILD_ID 2 MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED); MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED); void before () { // Setup the buttons pinMode(PRIMARY_BUTTON_PIN, INPUT); pinMode(SECONDARY_BUTTON_PIN, INPUT); // Activate internal pull-ups digitalWrite(PRIMARY_BUTTON_PIN, HIGH); digitalWrite(SECONDARY_BUTTON_PIN, HIGH); pinMode(LED_PIN, OUTPUT); } void setup() { } void presentation() { sendSketchInfo(SKETCH_NAME, SKETCH_MAJOR_VER "." SKETCH_MINOR_VER); present(PRIMARY_CHILD_ID, S_DOOR); present(SECONDARY_CHILD_ID, S_DOOR); } void loop() { uint8_t value; static uint8_t sentValue=2; static uint8_t sentValue2=2; // Short delay to allow buttons to properly settle sleep(5); value = digitalRead(PRIMARY_BUTTON_PIN); if (value != sentValue) { // Value has changed from last transmission, send the updated value digitalWrite(LED_PIN, HIGH); delay (5); send(msg.set(value==HIGH)); digitalWrite(LED_PIN, LOW); sentValue = value; } value = digitalRead(SECONDARY_BUTTON_PIN); if (value != sentValue2) { // Value has changed from last transmission, send the updated value digitalWrite(LED_PIN, HIGH); delay (5); send(msg2.set(value==HIGH)); digitalWrite(LED_PIN, LOW); sentValue2 = value; } // Sleep until something happens with the sensor sleep(PRIMARY_BUTTON_PIN-2, CHANGE,SECONDARY_BUTTON_PIN-2, CHANGE, 7000);how make it...???
also interrupt must working correctly.
please help me with my code.
tnx
Peter -
@ustredna , try changing this line:
send(msg.set(value==HIGH));
by
send(msg.set(value));
The same for msg2 line:
send(msg2.set(value==HIGH));
to
send(msg2.set(value));
And if you only need to update the GW on every 7 seconds (and not immediately), change the sleep:
sleep( 7000 ) ;
Hope it helps!
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