Navigation

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

    Best posts made by martins

    • RE: Sleep function breaks code

      OK it's working. Main fix I think is I used the new 2.1.1 library and all comms to the RFM69 radio seems to be fixed.

      Current code:

      • DESCRIPTION
      • Simple binary switch example
      • Connect button or door/window reed switch between
      • digitial I/O pin 3 (BUTTON_PIN below) and GND.
      • http://www.mysensors.org/build/binary
        */

      // Enable debug prints to serial monitor
      #define MY_DEBUG

      // Enable and select radio type attached
      // #define MY_RADIO_NRF24
      #define MY_RADIO_RFM69
      #define MY_RFM69_FREQUENCY RF69_433MHZ
      #define MY_IS_RFM69HW

      #if F_CPU == 8000000L
      #define MY_BAUD_RATE 38400
      #endif

      #include <SPI.h>
      #include <MySensors.h>

      #define CHILD_ID 3
      #define BUTTON_PIN 3 // Arduino Digital I/O pin for button/reed switch

      int oldValue=-1;

      // Change to V_LIGHT if you use S_LIGHT in presentation below
      MyMessage msg(CHILD_ID,V_TRIPPED);

      void setup()
      {
      // Setup the button
      pinMode(BUTTON_PIN,INPUT);
      // Activate internal pull-up
      digitalWrite(BUTTON_PIN,HIGH);
      }

      void presentation() {
      // Register binary input sensor to gw (they will be created as child devices)
      sendSketchInfo("Binary Sensor", "1.0");
      // You can use S_DOOR, S_MOTION or S_LIGHT here depending on your usage.
      // If S_LIGHT is used, remember to update variable type you send in. See "msg" above.
      present(CHILD_ID, S_DOOR);
      // Send the sketch version information to the gateway and Controller
      }

      // Check if digital input has changed and send in new value
      void loop()
      {
      int value = digitalRead(BUTTON_PIN);
      #ifdef MY_DEBUG
      Serial.println("Sensor Value");
      Serial.println(value);
      #endif
      send(msg.set(value==HIGH ? 1 : 0));
      sleep(BUTTON_PIN-2, CHANGE, 0);
      }

      Thanks,
      Martin

      posted in Troubleshooting
      martins
      martins