LowPowerLab Forum

Hardware support => General topics => Topic started by: ssmall on January 31, 2018, 09:24:55 AM

Title: GarageMote Push Button Switch Purpose
Post by: ssmall on January 31, 2018, 09:24:55 AM
In the latest revision of the GarageMote there is a push button switch but I am not sure what it is used for.  I looked in the GarageMote sketch and I don't see any references to the push button.  Is the push button hooked up to a pin on the Moteino?
Title: Re: GarageMote Push Button Switch Purpose
Post by: sparky on January 31, 2018, 11:17:55 AM
I think I read somewhere in the blog that it was for future use.
Title: Re: GarageMote Push Button Switch Purpose
Post by: Felix on January 31, 2018, 11:22:19 AM
It's a general purpose button that can be used for anything.
It can be useful to have such a button on the mote itself, in case you want to send a "refresh" or action the door, or do some debugging action, or whatever else.
The button is connected to GND and D3. So D3 should be setup as an INPUT_PULLUP, and an interrupt can be tied to INT1 (D3 is hardware interrupt 1), as seen in other examples.
Title: Re: GarageMote Push Button Switch Purpose
Post by: sparky on January 31, 2018, 11:23:03 AM
Here is what I found;

◾R2 kit includes a momentary button between GND and D3 – no code released for this (yet) but this can  be used to add a function to your GarageMote – like SYNC-ing with a SwitchMote so you can open/close your garage from a SwitchMote button, how cool is that!

Founds here;

https://lowpowerlab.com/2015/01/13/garagemote-r2-released/

Title: Re: GarageMote Push Button Switch Purpose
Post by: Felix on January 31, 2018, 12:51:59 PM
Yup, sync'ing with a SwitchMote was my design time idea :)
Never got around to doing it myself, instead I wanted to make this happen in the Gateway UI. But anyway such a feature would be useful where SwitchMotes are used standalone without a Gateway.
Title: Re: GarageMote Push Button Switch Purpose
Post by: ssmall on January 31, 2018, 02:15:50 PM
Thanks for the update. I forgot to check the blog. I will send if I can use it to open/close the door.
Title: Re: GarageMote Push Button Switch Purpose
Post by: Felix on January 31, 2018, 04:27:55 PM
Quote from: ssmall on January 31, 2018, 02:15:50 PM
Thanks for the update. I forgot to check the blog. I will send if I can use it to open/close the door.

Don't forget to debounce it. For an open/close action, just putting a timer would be enough to do that (ie only trigger your action once every ... few seconds - any repeats within that time are ignored).
Title: Re: GarageMote Push Button Switch Purpose
Post by: ssmall on January 31, 2018, 06:08:36 PM
I was going to look into debouncing the button press.  I think there are examples in the LowPowerLab git repo.
Title: Re: GarageMote Push Button Switch Purpose
Post by: Felix on January 31, 2018, 07:01:34 PM
Yup, several.
The MotionMote example (https://github.com/LowPowerLab/RFM69/blob/master/Examples/MotionMote/MotionMote.ino) has one that is just like what you need, except in the GarageMote case you need attachInterrupt on FALLING edge:

attachInterrupt(MOTION_IRQ, motionIRQ, FALLING);

And setup D3 as INPUT_PULLUP.
Title: Re: GarageMote Push Button Switch Purpose
Post by: ssmall on February 02, 2018, 10:00:00 PM
Rather than using interrupts I used the button handling code from the MightyBoost:

I used the following in setup():
  pinMode(BUTTON, INPUT_PULLUP);

This is used in loop()

  // Check for button press
  int reading = digitalRead(BUTTON);
  NOW = millis();

  if (reading != lastValidReading && NOW - lastValidReadingTime > 200)
  {
    DEBUGln("Button Pressed");
   
    lastValidReading = reading;
    lastValidReadingTime = NOW;
   
    if (reading == LOW)
    {
      DEBUGln("Button Still Pressed");
      //make sure the button is held down for at least 'BUTTON_HOLD_TIME' before taking action (this is to avoid accidental button presses and consequently Pi shutdowns)
      NOW = millis();
      while (millis() - NOW < BUTTON_HOLD_TIME)
      {
        delay(10); if (digitalRead(BUTTON) != LOW) return;
      }

      DEBUGln("Action garage door");
      //BUTTON_HOLD_TIME is satisfied, now action the door.
      pulseRelay();
    }
  }
Title: Re: GarageMote Push Button Switch Purpose
Post by: Felix on February 03, 2018, 06:25:44 PM
Whatever works...  ;)