Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
martinsM

martins

@martins
About
Posts
35
Topics
5
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Sleep function breaks code
    martinsM martins

    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

    Troubleshooting
  • Login

  • Don't have an account? Register

  • Login or register to search.
  • First post
    Last post
0
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular