GarageMote Push Button Switch Purpose

Started by ssmall, January 31, 2018, 09:24:55 AM

ssmall

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?

sparky

I think I read somewhere in the blog that it was for future use.

Felix

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.

sparky

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/


Felix

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.

ssmall

Thanks for the update. I forgot to check the blog. I will send if I can use it to open/close the door.

Felix

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).

ssmall

I was going to look into debouncing the button press.  I think there are examples in the LowPowerLab git repo.

Felix

Yup, several.
The MotionMote example 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.

ssmall

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();
    }
  }

Felix