Navigation

    • Register
    • Login
    • OpenHardware.io
    • Categories
    • Recent
    • Tags
    • Popular
    1. Home
    2. Grzegorz B
    • Profile
    • Following
    • Followers
    • Topics
    • Posts
    • Best
    • Groups

    Grzegorz B

    @Grzegorz B

    1
    Reputation
    2
    Posts
    2
    Profile views
    0
    Followers
    0
    Following
    Joined Last Online

    Grzegorz B Follow

    Best posts made by Grzegorz B

    • RE: My Slim 2AA Battery Node

      @mfalkvidd Thanks! now its works like a charm 😄

      posted in My Project
      Grzegorz B
      Grzegorz B

    Latest posts made by Grzegorz B

    • RE: My Slim 2AA Battery Node

      @mfalkvidd Thanks! now its works like a charm 😄

      posted in My Project
      Grzegorz B
      Grzegorz B
    • RE: My Slim 2AA Battery Node

      Hello, will there be a good soul that will help improve the program? I know what the error is but I have no idea how to correct it.

        interruptReturn = sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, ONE_DAY_SLEEP_TIME);
      

      when i change

      PRIMARY_BUTTON_PIN
      

      the interruptReturn = 1, but when i change

      SECONDARY_BUTTON_PIN
      

      the interruptReturn = 0.
      My question is how can i chane it to send 1 and 1 by both contactrons.

      Full code:

      //#define MY_DEBUG
      #define MY_RADIO_NRF24
      #define MY_NODE_ID 100
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      #include <MySensors.h>
      #include "Vcc.h"
      
      #define SKETCH_NAME "WindowSlimSensor2pcs_smallR"
      
      #define PRIMARY_CHILD_ID 1
      #define PRIMARY_BUTTON_PIN 2
      #define SECONDARY_CHILD_ID 2
      #define SECONDARY_BUTTON_PIN 3
      #define BATTERY_REPORT_DAY 2   // Desired heartbeat interval when inactive. Maximum heartbeat/report interval is equal to this due to the dayCounter.
      #define BATTERY_REPORT_BY_IRT_CYCLE 10  // Adjust this according to usage frequency.
      #define ONE_DAY_SLEEP_TIME 86400000
      
      //#define BATTERY 3
      
      MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
      MyMessage msg2(SECONDARY_CHILD_ID, V_TRIPPED);
      //MyMessage msg3(BATTERY, V_CUSTOM);
      
      int dayCounter = 0;
      int irtCounter = 0;
      bool interruptReturn=false;
      const float VccMin   = 1.7;           // Minimum expected Vcc level, in Volts.
      const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
      const float VccCorrection = 3.43 / 3.455;  // Measured Vcc by multimeter divided by reported Vcc
      
      
      const int32_t report_interval = 8640000; // 1day -> h * m * s * ms NOTICE: milliseconds, not microseconds!
      
      Vcc vcc(VccCorrection);
      //Vcc vcc;
      #ifdef MY_DEBUG
      void before(){
          Serial.begin(9600);
      }
      #endif
      
      void setup()
      {
          pinMode(PRIMARY_BUTTON_PIN, INPUT);
          pinMode(SECONDARY_BUTTON_PIN, INPUT);
            //EXTERNAL pull-ups
          digitalWrite(PRIMARY_BUTTON_PIN, LOW);
          digitalWrite(SECONDARY_BUTTON_PIN, LOW);  
      }
      
      void presentation()
      {
          sendSketchInfo(SKETCH_NAME, __DATE__);
          present(PRIMARY_CHILD_ID, S_DOOR, "Lewe Okno");
          present(SECONDARY_CHILD_ID, S_DOOR, "Prawe Okno");
        //  present(BATTERY, S_CUSTOM);
      }
      
      void loop()
      
      {
          uint8_t reedState;
          uint8_t reedState2;
          static uint8_t lastReedState = 2;
          static uint8_t lastReedState2 = 2;
          sleep(5); // Short delay to allow buttons to properly settle
          reedState = digitalRead(PRIMARY_BUTTON_PIN);
          sleep(5); // Short delay to allow buttons to properly settle
          reedState2 = digitalRead(SECONDARY_BUTTON_PIN);
      
        if (!interruptReturn) { // Woke up by timer (or first run)
          dayCounter++; 
          if (dayCounter >= BATTERY_REPORT_DAY) {
                dayCounter = 0;
                sendBatteryReport();
          }
        }
        else {    // Woke up by pin change
                  irtCounter++;
              sleep(5); 
        
            // Woke up by pin change
            if (reedState != lastReedState) {
              send(msg.set(reedState==HIGH ? 1 : 0));
              lastReedState = reedState;
          }
            if (reedState2 != lastReedState2) {
              send(msg2.set(reedState2==HIGH ? 1 : 0));
              lastReedState2 = reedState2;
          }
            if (irtCounter>=BATTERY_REPORT_BY_IRT_CYCLE) {
              irtCounter=0;
              sendBatteryReport();
            }
          
        }
      
        // Sleep until something happens with the sensor,   or one sleep_time has passed since last awake.
        interruptReturn = sleep(PRIMARY_BUTTON_PIN-2, CHANGE, SECONDARY_BUTTON_PIN-2, CHANGE, ONE_DAY_SLEEP_TIME);
        
      } 
      
      void sendBatteryReport() {
                uint8_t batteryPercent = (uint8_t)vcc.Read_Perc(VccMin, VccMax);
                sendBatteryLevel(batteryPercent);
      }
      
      
      posted in My Project
      Grzegorz B
      Grzegorz B