Jump to content



Photo
- - - - -

Multi Function Power Button Guide


  • Please log in to reply
No replies to this topic

#1 Vanlon

Vanlon

    Enthusiast

  • Platinum Supporter
  • 61 posts
  • Location:St. Albert, Alberta

  • Flag: Canada

  • Favorite Pinball: CannonBall

Posted 26 March 2020 - 02:36 AM

I came up with a solution for my power button and it seems to be working quite well so I figured I would share it.

 

Little back story on it, neither of my monitors come on when the main power is switched on so I would have to manually turn them on with the buttons.  I discovered that you can't just hook them all together to one button to turn everything on, there is some different voodoo in each button that makes it work.

I didn't want to have multiple buttons under the cabinet that I couldn't remember which was which either.  This led me to do some head scratching, how do you press three buttons at once, then stumbled on this solution.

 

So what this does is with one button you get 3 functions: Single Click, Double Click and Long Press!

I uses an Arduino board, I used a Nano that I put together with a regular 4 channel relay board.  I would have liked something smaller that didn't click so much but haven't managed to find something that does that. 

I'm not going to get into how I set up the Arduino, there are a million tutorials on that.

 

I soldered small wires directly to the buttons on the TV's and hooked them to the NO and Common pins on the relays.

The Arduino board is connected to my CPU and I have the BIOS set to supply USB power when it's off so the Arduino always stays on.

 

I chose to use 1 click for turn everything on or off.  1 relay for the CPU, 1 for the Playfield and 1 for the Back Glass.

Double click turns off or on the Playfield and Backglass, so I can VNC from my main PC without needing them on

Long Press toggles night mode, you can use it for whatever you like of course.  Toggle all your DOF, turn your fan on whatever. 

 

The first two functions I set as momentary presses of buttons, the last one is a latching toggle, press for on, press again for off.

 

Thingiverse Files

 

IMG-20200328-095137.jpg IMG-20200328-095144-1.jpg

 

Here is my code:

/*
 * One Button library used for Visual Pinball multi function power button
 * 
 * created by Matthias Hertel
 * Find the library here: https://github.com/mathertel/OneButton
 *
 * code modified for Visual Pinball by Vanlon
 */
 
#include "OneButton.h"                              //we need the OneButton library
int pbutton = 12;                                   //push button pin
int relayPin = 4;                                   //relay pins
int relayPin2 = 5; 
int relayPin3 = 6;
int relayPin4 = 7;

int status = false;                                 //initalize and set the status for night mode toggle        
 
OneButton button(pbutton, true);                    //attach a button to the library

 
void setup() {

  pinMode(pbutton, INPUT_PULLUP); 
  pinMode(relayPin, OUTPUT);                        // sets the digital pin as output
  pinMode(relayPin2, OUTPUT);                       // sets the digital pin as output
  pinMode(relayPin3, OUTPUT);                       // sets the digital pin as output
  pinMode(relayPin4, OUTPUT);                       // sets the digital pin as output
     
  button.attachDoubleClick(doubleclick);            // link the function to be called on a doubleclick event.
  button.attachClick(singleclick);                  // link the function to be called on a singleclick event.
  button.attachLongPressStart(longclick);           // link the function to be called on a longpress event.
}
 
void loop() {
 
  button.tick();                                    // check the status of the button
 
  delay(10);                                        // a short wait between checking the button
} // loop
 
void singleclick(){                                 //using single click to turn on pinball machine
 digitalWrite(relayPin,HIGH);                       //toggle CPU    
 digitalWrite(relayPin4,HIGH);                      //toggle playfield                            
 delay(500);                                        //hold the button down for half a second
 digitalWrite(relayPin,LOW);                        //release button    
 digitalWrite(relayPin4,LOW);                       //release button          
 
 digitalWrite(relayPin3,HIGH);                      //toggle backglass
 delay(2500);                                       //my backglass requres a hold before it will shut off, doesn't affect turning on
 digitalWrite(relayPin3,LOW); 
}

void doubleclick() {                                //using double click to turn off display's
 digitalWrite(relayPin4,HIGH);                      //toggle playfield      
 delay(500);
 digitalWrite(relayPin4,LOW); 
 
 digitalWrite(relayPin3,HIGH);                      //toggle backglass
 delay(2500);                                       
 digitalWrite(relayPin3,LOW); 
} 

void longclick(){                                   //using long click to latch night mode on or off
  status = !status;                                 //reverse the status in memory
  digitalWrite(relayPin2, status);
}    


Edited by Vanlon, 02 June 2020 - 03:16 AM.