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
P

PDP8

@PDP8
About
Posts
6
Topics
1
Shares
0
Groups
0
Followers
0
Following
0

Posts

Recent Best Controversial

  • Multiple switch inputs
    P PDP8

    Hmm, I've changed it to S_DOOR now. But I still can turn it on and off in Domoticz.
    I guess this is a Domoticz thing and has nothing to do with MySensors... Weird...

    Hardware

  • Multiple switch inputs
    P PDP8

    Thanks for the comment, I will look at it.

    Another question, the inputs look exactly like an output in domoticz.
    I can even switch on the lamp with the mouse. Of course there is nothing happening
    because it is an input. But it is a bit confusing. Is this a Domoticz setting? Or can I change
    something in the MySensors code for this? Thanks!

    0_1532950762825_inputs and outputs.png

    Hardware

  • Multiple switch inputs
    P PDP8

    Well to make three inputs I've come to this using the code you mentioned...
    I've removed the invert function because I could get Domotics invert the
    monitoring. And I've added an initial read at startup. Because at powering-up
    the switches were not read. Any comments? Regards!

    
    // Enable debug prints to serial monitor
    #define MY_DEBUG
    
    // Enable serial gateway
    #define MY_GATEWAY_SERIAL
    
    #include <SPI.h>
    #include <MySensors.h>
    #include <Bounce2.h>
    
    // Define Sensor ID's
    #define KNOB_A_ID 1   // Id of the sensor child
    #define KNOB_B_ID 2   // Id of the sensor child
    #define KNOB_C_ID 3   // Id of the sensor child
    
    
    // Define buttons
    const int buttonPinA = 10;
    const int buttonPinB = 11;
    const int buttonPinC = 12;
    
    // Define Variables
    int oldValueA = 0;
    int oldValueB = 0;
    int oldValueC = 0;
    bool stateA = false;
    bool stateB = false;
    bool stateC = false;
    int trigger = 0;
    
    
    Bounce debouncerA = Bounce();
    Bounce debouncerB = Bounce();
    Bounce debouncerC = Bounce();
    
    MyMessage msgA(KNOB_A_ID, V_STATUS);
    MyMessage msgB(KNOB_B_ID, V_STATUS);
    MyMessage msgC(KNOB_C_ID, V_STATUS);
    
    void setup()
    {
    
      pinMode(buttonPinA, INPUT_PULLUP); // Setup the button Activate internal pull-up
      pinMode(buttonPinB, INPUT_PULLUP); // Setup the button Activate internal pull-up
      pinMode(buttonPinC, INPUT_PULLUP); // Setup the button Activate internal pull-up
    
    
      // After setting up the buttons, setup debouncer
      debouncerA.attach(buttonPinA);
      debouncerA.interval(5);
      debouncerB.attach(buttonPinB);
      debouncerB.interval(5);
      debouncerC.attach(buttonPinC);
      debouncerC.interval(5);
    
    
    
        /*--------------------- Added these lines for toggle switch-------------------------*/
      oldValueA = digitalRead(buttonPinA);  // set oldValueA to the current status of the toggle switch
      oldValueB = digitalRead(buttonPinB);  // set oldValueB to the current status of the toggle switch
      oldValueC = digitalRead(buttonPinC);  // set oldValueC to the current status of the toggle switch  
     
    }
    
    void presentation()  {
      // Send the sketch version information to the gateway and Controller
      sendSketchInfo("2x bistable button", "1.1");
    
      // Register all sensors to gw (they will be created as child devices)
      present(KNOB_A_ID, S_LIGHT);
      present(KNOB_B_ID, S_LIGHT);
      present(KNOB_C_ID, S_LIGHT);  
    
    }
    
    
    
    void loop()
    {
      if (trigger == 0)
        {
          debouncerA.update(); // Get the startup valueA
          int valueA = debouncerA.read();
          send(msgA.set(valueA==HIGH ? 0 : 1));
    
          debouncerB.update(); // Get the startup valueB
          int valueB = debouncerB.read();
          send(msgB.set(valueB==HIGH ? 0 : 1));
    
          debouncerC.update(); // Get the startup valueC
          int valueC = debouncerC.read();
          send(msgC.set(valueC==HIGH ? 0 : 1));
    
          trigger = 1;
        }
    
    
    
      debouncerA.update();
      // Get the update valueA
      int valueA = debouncerA.read();
     
      if (valueA != oldValueA) {
         // Send in the new valueA
         send(msgA.set(valueA==HIGH ? 0 : 1));
         oldValueA = valueA;
      }
    
      debouncerB.update();
      // Get the update valueB
      int valueB = debouncerB.read();
     
      if (valueB != oldValueB) {
         // Send in the new valueB
         send(msgB.set(valueB==HIGH ? 0 : 1));
         oldValueB = valueB;
      }
    
      debouncerC.update();
      // Get the update valueC
      int valueC = debouncerC.read();
     
      if (valueC != oldValueC) {
         // Send in the new valueC
         send(msgC.set(valueC==HIGH ? 0 : 1));
         oldValueC = valueC;
      }  
    
    }
    
    
    Hardware

  • Multiple switch inputs
    P PDP8

    @rejoe2 said in Multiple switch inputs:

    Thanks, I will dive into the code then :-)

    Hardware

  • Multiple switch inputs
    P PDP8

    Thanks, it seems the switches also turn on the relays directly?
    I have to figure out the code. I just want to have independent switch inputs.

    If there is some code which has only switches it would help a lot :)

    Regards

    Hardware

  • Multiple switch inputs
    P PDP8

    Hello all,

    I'm new here and also new to MySensors. I got here trough Domoticz.

    At the moment I have an Arduino Nano running and configured as a serial gateway trough USB.
    I've combined the relay and temperature sketch and now I can use a ds18b20 and 8 relays simultaneous on that board.

    But I want to add some switches too. I've seen a button sketch but that is for just one button.
    I've read about expanding this sketch would give problems with the debounce code.

    Does anyone have an example for multiple switches on one Arduino?

    Thanks in advance!

    Hardware
  • Login

  • Don't have an account? Register

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