Pages: [1]   Go Down
Author Topic: Button pulled low when pressed  (Read 328 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Full Member
***
Karma: 0
Posts: 104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

0
Offline Offline
Sr. Member
****
Karma: 0
Posts: 360
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Use an internal pullup resistor:

Code:
#define PINNUM 9

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

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

Offline Offline
Full Member
***
Karma: 0
Posts: 104
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It worked. Thanks.
Logged

Pages: [1]   Go Up
Jump to: