A switch between two digital pins, is it safe?

I'm planning to connect a switch to 2 input digital pins with the following code:

  pinMode(pin0, INPUT_PULLUP);
  pinMode(pin1, OUTPUT);
  digitalWrite(pin1, LOW);

According to the datasheet of Atmega32U4 the internal pull-up resistors have a value between 20kΩ and 50kΩ, so theoreticaly it should be safe, but I need your advice before trying to connect it like that.

Hi, I see one input and one output....

Please supply [u]full code[/u] and a [u]circuit diagram[/u] of your project showing your switches and output.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Thanks.. Tom.... :)

Yes, it's safe. Just make sure that you never have both pins as output and set them to opposite levels.

#include "Keyboard.h"

const int pin0 = 0;
const int pin1 = 1;
bool pin0pressed = false;

void setup()
{
  pinMode(pin0, INPUT_PULLUP);
  pinMode(pin1, OUTPUT);
  digitalWrite(pin1, LOW);
}

void loop()
{
    if (digitalRead(pin0) == LOW & pin0pressed == false)
    {
        Keyboard.press(KEY_DOWN_ARROW);
        pin0pressed = true;
        delay(5); //debounce
    }
    if (digitalRead(pin0) == HIGH & pin0pressed == true)
    {
        Keyboard.release(KEY_DOWN_ARROW);
        pin0pressed = false;
        delay(5); //debounce
    }
    delay(1);
}

Don't judge my lazy "debounce" it's just a quick 1minute sketch. So it's safe you are saying? Thanks, I will try that and pray it won't go down in flames :)

oomek: Don't judge my lazy "debounce" it's just a quick 1minute sketch. So it's safe you are saying? Thanks, I will try that and pray it won't go down in flames :)

What you are doing is a little unconventional...

You could just as easily bridge the switch across your input pin and the 3V3 pin, no?

(deleted)

The reason for doing it like that is that I have already premade 2 pin arcade button harnesses. I'm planning to use my A-Star boar as a supplementary board to my IPAC2 controller. I just need 4 extra buttons, so I'm not sad about the reason I'm wasting some i/o pins.

I hope those connectors can handle the current!

:grinning: