<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[[SOLVED] Node with 2 Buttons, both debounced, always having the same status]]></title><description><![CDATA[<p dir="auto">Hey,</p>
<p dir="auto">I tried to programm a nano to have 2 relays and 2 buttons for controlling them. But every time, I change the status of one of the switches, the other is changed, too. Maybe it is something about the debouncing, but afaik you can create 2 instances of debounce.<br />
I minimized the sketch to avoid problems with further code, but still the same:</p>
<pre><code>// Simple binary switch example 
// Connect button or door/window reed switch between 
// digitial I/O pin 3 (BUTTON_PIN below) and GND.

#include &lt;MySensor.h&gt;
#include &lt;SPI.h&gt;
#include &lt;Bounce2.h&gt;

#define CHILD_ID 4
#define BUTTON_PIN  4  // Arduino Digital I/O pin for button/reed switch
#define CHILD_ID2 5
#define BUTTON2_PIN  5  // Arduino Digital I/O pin for button/reed switch

MySensor gw;
Bounce debouncer = Bounce(); 
Bounce debouncer2 = Bounce(); 
int oldValue=-1;
int oldValue2=-1;

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

void setup()  
{  
  gw.begin();

 // Setup the button
  pinMode(BUTTON_PIN,INPUT);
  // Activate internal pull-up
  digitalWrite(BUTTON_PIN,HIGH);
  pinMode(BUTTON2_PIN,INPUT);
  // Activate internal pull-up
  digitalWrite(BUTTON2_PIN,HIGH);
  
  // After setting up the button, setup debouncer
  debouncer.attach(BUTTON_PIN);
  debouncer.interval(5);
  debouncer2.attach(BUTTON2_PIN);
  debouncer2.interval(5);
  
  // Register binary input sensor to gw (they will be created as child devices)
  // 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.
  gw.present(CHILD_ID, S_LIGHT);  
  gw.present(CHILD_ID2, S_LIGHT);  
}


//  Check if digital input has changed and send in new value
void loop() 
{
  debouncer.update();
  debouncer2.update();
  // Get the update value
  int value = debouncer.read();
  int value2 = debouncer2.read();
 
  if (value != oldValue) {
     // Send in the new value
     gw.send(msg.set(value==HIGH ? 1 : 0));
     oldValue = value;
  }
  if (value2 != oldValue2) {
     // Send in the new value
     gw.send(msg2.set(value2==HIGH ? 1 : 0));
     oldValue2 = value2;
  }
} 
</code></pre>
<p dir="auto">I would be greatful for any kind of hint.</p>
]]></description><link>https://forum.mysensors.org/topic/2126/solved-node-with-2-buttons-both-debounced-always-having-the-same-status</link><generator>RSS for Node</generator><lastBuildDate>Fri, 06 Nov 2026 21:49:31 GMT</lastBuildDate><atom:link href="https://forum.mysensors.org/topic/2126.rss" rel="self" type="application/rss+xml"/><pubDate>Wed, 07 Oct 2015 12:55:59 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to [SOLVED] Node with 2 Buttons, both debounced, always having the same status on Wed, 07 Oct 2015 19:16:46 GMT]]></title><description><![CDATA[<p dir="auto">Ok ;) Looked at the code earlier but couldn't find anything wrong.</p>
]]></description><link>https://forum.mysensors.org/post/22405</link><guid isPermaLink="true">https://forum.mysensors.org/post/22405</guid><dc:creator><![CDATA[hek]]></dc:creator><pubDate>Wed, 07 Oct 2015 19:16:46 GMT</pubDate></item><item><title><![CDATA[Reply to [SOLVED] Node with 2 Buttons, both debounced, always having the same status on Wed, 07 Oct 2015 18:18:44 GMT]]></title><description><![CDATA[<p dir="auto">OK I solved the problem: there was a litte solder brigde between PIN 4 and 5. I didn't checked that carefully before because I bought it with already soldered headers.</p>
]]></description><link>https://forum.mysensors.org/post/22397</link><guid isPermaLink="true">https://forum.mysensors.org/post/22397</guid><dc:creator><![CDATA[Anduril]]></dc:creator><pubDate>Wed, 07 Oct 2015 18:18:44 GMT</pubDate></item></channel></rss>