Go Down

Topic: Button pulled low when pressed (Read 356 times) previous topic - next topic

N314

I have a joystick shield from sparkfun.com.
Schematic: http://www.sparkfun.com/datasheets/DevTools/Arduino/Joystick_Shield-v12.pdf

The schematic has the 4 buttons connected to pins 3, 4, 5, and 6 on the arduino (Uno), and the other side of the butttons are connected to ground.

I know how to detect if the pin goes high, but the pin is low when the button is not pressed, and is still low when the button is pressed.

How do I figure out when the button is being pressed without external wiring on the shield?

Thanks

Aeturnalus

Use an internal pullup resistor:

Code: [Select]

#define PINNUM 9

void setup() {
  pinMode(PINNUM, INPUT); // set to input mode
  digitalWrite(PINNUM, HIGH); // set internal pullup
}

void loop() {
  bool isPressed = !digitalRead(PINNUM);
}

N314


Go Up