Go Down

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


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?



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);


Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131