# Hold push button to switch several outputs

**URL:** <https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184>\
**Category:** General Guidance\
**Created:** [March 1, 2025, 11:09am UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184 "2025-03-01T11:09:18Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![j3r03n85](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j3r03n85/32/1127095_2.png) [@j3r03n85](https://forum.arduino.cc/u/j3r03n85)\
**Post date:** [March 1, 2025, 11:09am UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/1 "2025-03-01T11:09:18Z")

</div>

Hello,

I was wondering if the next thing could ben done.  
I have a situation where I want to be able to switch situations on 3 outputs with 1 single push button.

I have and arduino connected to 2 leds (a red one and a green one) and I have another output.

The situation I want to create is when the arduino is powered the red LED is on, the green LED is off and the 3rd output is low.  
When holding the button for three seconds, I want the red led to switch off, the green LED to switch on and the 3rd output to go high.

When I press the button for 3 seconds again I want it to to go back to it's original situation again.

So I want it cycle between

Power on state:  
Red LED on  
Green LED off  
3rd output low

Press for 3 seconds  
Red LED off  
Green LED on  
3rd output high

Press for 3 seconds  
switch it back, and so on and so on.

I have a situation when I press the button it already does this.  
But I want the situation to be like I have to hold the button for 3 seconds.

How can I achieve this ?

---

<div class="post-metadata">

**Author:** ![lastchancename](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/lastchancename/32/215426_2.png) [@lastchancename](https://forum.arduino.cc/u/lastchancename)\
**Post date:** [March 1, 2025, 12:01pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/2 "2025-03-01T12:01:37Z")

</div>

Nicely explained project.  
It’s a great starter for a new user.

To start out, I’d suggest working through the **built-in tutorials** in the Arduino IDE

Try to understand one thing at a time, then stitch them together.

While plugging through the lessons, play with the **miliis** () function for your timing. **delay** )) is useful but _only_ in the simplest situations when you understand how it works,

Come back to this same thread to ask more questions about the same project.

---

<div class="post-metadata">

**Author:** ![j3r03n85](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j3r03n85/32/1127095_2.png) [@j3r03n85](https://forum.arduino.cc/u/j3r03n85)\
**Post date:** [March 1, 2025, 12:50pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/3 "2025-03-01T12:50:33Z")

</div>

Thank you so much!!

I have it figured out now!

```arduino
/*
  j3r03n85's Famciom/NES clone 50/60Hz Video mode switcher for TA-02NP PPU's

  In this sketch I use an arduino to switch PIN 16 of my TA-02NP clone NES PPU from 50 to 60Hz
  using the reset button.
  The reset button still acts as a normal reset button on the console, but when you hold it for
  a brief moment you'll see the power LED changing color and the PPU will be switched from
  50 to 60Hz.
  When holding the reset button again for the same amount of time will switch it back to the mode
  it was before.
  The main reason I used an arduino is that I didn't want to drill a hole in my case for a
  physical switch.
  
*/

// constants won't change. They're used here to set pin numbers:
const int buttonPin = 8; // the number of the pushbutton pin
const int REDled = 11; // the number of the RED LED pin
const int GREENled = 12; // the number of the GREEN LED pin
const int VIDMODE = 3; // the number of the Video output mode

// Variables will change:
int REDledState = HIGH; // the current state of the output pin
int GREENledState = LOW;
int VIDMODEState = LOW;
int buttonState; // the current reading from the input pin
int lastButtonState = LOW; // the previous reading from the input pin

// the following variables are unsigned longs because the time, measured in
// milliseconds, will quickly become a bigger number than can be stored in an int.
unsigned long lastDebounceTime = 0; // the last time the output pin was toggled
unsigned long debounceDelay = 1000; // the debounce time; increase if the output flickers

void setup() {
  pinMode(buttonPin, INPUT);
  pinMode(REDled, OUTPUT);
  pinMode(GREENled, OUTPUT);
  pinMode(VIDMODE, OUTPUT);

  // set initial LED state
  digitalWrite(REDled, REDledState);
  digitalWrite(GREENled, GREENledState);
  digitalWrite(VIDMODE, VIDMODEState);
}

void loop() {
  // read the state of the switch into a local variable:
  int reading = digitalRead(buttonPin);

  // check to see if you just pressed the button
  // (i.e. the input went from LOW to HIGH), and you've waited long enough
  // since the last press to ignore any noise:

  // If the switch changed, due to noise or pressing:
  if (reading != lastButtonState) {
    // reset the debouncing timer
    lastDebounceTime = millis();
  }

  if ((millis() - lastDebounceTime) > debounceDelay) {
    // whatever the reading is at, it's been there for longer than the debounce
    // delay, so take it as the actual current state:

    // if the button state has changed:
    if (reading != buttonState) {
      buttonState = reading;

      // only toggle the LED if the new button state is HIGH
      if (buttonState == HIGH) {
        REDledState = !REDledState;
        GREENledState = !GREENledState;
        VIDMODEState = !VIDMODEState;
      }
    }
  }

  // set the LED:
  digitalWrite(REDled, REDledState);
  digitalWrite(GREENled, GREENledState);
  digitalWrite(VIDMODE, VIDMODEState);

  // save the reading. Next time through the loop, it'll be the lastButtonState:
  lastButtonState = reading;
}

```

The project I am working on is a famicom clone which has a CPU that can switch between 50 and 60hz video mode by having one pin of the PPU tied to either GND (50Hz) or +5V (60Hz)

Normally it would be easier to just lift that pin and put a toggle switch on it, but I don't want to drill a hole in this case.  
So I was thinking to put the arduino in as the middle man and using the already existing reset button and replacing the power LED with a 2 color LED.  
So when powering on it it will be in the original state (50Hz) and the LED will be RED, and when holding the reset button for 3 seconds, it will switch to 60Hz and my led will be green.  
If I want to swtich back to 50Hz, all I have to do is hold that reset button for 3 seconds again.

Now all I have to do is check how much current that one of the ppu draws.

[EDIT] - the pin uses less than 4mA so I can hook it up to an I/O pin on the arduino safely

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [March 1, 2025, 1:25pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/4 "2025-03-01T13:25:08Z")

</div>

> [@j3r03n85](#):
>
> Normally it would be easier to just lift that pin and put a toggle switch on it, but I don't want to drill a hole in this case.

Skip the Arduino, put a latching magnetic reed switch on the inside of the case, and use a magnet to switch it from outside.

---

<div class="post-metadata">

**Author:** ![j3r03n85](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j3r03n85/32/1127095_2.png) [@j3r03n85](https://forum.arduino.cc/u/j3r03n85)\
**Post date:** [March 1, 2025, 1:31pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/5 "2025-03-01T13:31:56Z")

</div>

will that achieve my goal?  
Holing a button for an x amount of time, change the color of the LED so I know the video mode changes?

---

<div class="post-metadata">

**Author:** ![camsysca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/camsysca/32/1015228_2.png) [@camsysca](https://forum.arduino.cc/u/camsysca)\
**Post date:** [March 1, 2025, 1:42pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/6 "2025-03-01T13:42:02Z")

</div>

If that's what you really need, probably not. But, you stated that the reason you weren't using a switch is because you didn't want to drill a hole in the case, so I gave you an option. YMMV.

---

<div class="post-metadata">

**Author:** ![j3r03n85](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j3r03n85/32/1127095_2.png) [@j3r03n85](https://forum.arduino.cc/u/j3r03n85)\
**Post date:** [March 1, 2025, 1:43pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/7 "2025-03-01T13:43:19Z")

</div>

Ah I see !

Gonna try this code on my real arduino now.  
It works in my simulator.

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [March 1, 2025, 2:21pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/8 "2025-03-01T14:21:46Z")

</div>

> [@j3r03n85](#):
>
> It works in my simulator.

Tell us about your simulator. Pst a link to it!

Our do you mean your simulation running on some simulator we may know about?

If so, woyncha post a link to your simulation?

a7

---

<div class="post-metadata">

**Author:** ![j3r03n85](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j3r03n85/32/1127095_2.png) [@j3r03n85](https://forum.arduino.cc/u/j3r03n85)\
**Post date:** [March 1, 2025, 2:31pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/9 "2025-03-01T14:31:59Z")

</div>

Yeah I used an online simulator to check my code.

you can find it here:

> **[Arduino on Wokwi - Online ESP32, STM32, Arduino Simulator](https://wokwi.com/arduino)**
>
> IoT and Embedded System Simulator: ESP32, STM32, Arduino, Raspberry Pi Pico, displays, sensors, motors and WiFi simulation.

---

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [March 1, 2025, 2:40pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/10 "2025-03-01T14:40:51Z")

</div>

> [@j3r03n85](#):
>
> you can find it here:

I am familiar with that one. Post a link to your simulation.

TIA

a7

---

<div class="post-metadata">

**Author:** ![j3r03n85](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/j3r03n85/32/1127095_2.png) [@j3r03n85](https://forum.arduino.cc/u/j3r03n85)\
**Post date:** [March 1, 2025, 2:42pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/11 "2025-03-01T14:42:30Z")

</div>

> **[NES PPU - Switcher - Wokwi ESP32, STM32, Arduino Simulator](https://wokwi.com/projects/424234204513993729)**
>
> Run IoT and embedded projects in your browser: ESP32, STM32, Arduino, Pi Pico, and more. No installation required!

in the sim I use a yellow led on the video output pin to see how it responds

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [August 28, 2025, 2:42pm UTC](https://forum.arduino.cc/t/hold-push-button-to-switch-several-outputs/1359184/12 "2025-08-28T14:42:35Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
