Assigning Pins for buttons - Not so simple?

I was just playing with Arduino, I assigned pin 2,3 to be my buttons. Works fine. If I try and assign 4 and 5 doesn’t work. If I assign a 3rd on to pin 11 that works.

Is there something fundamental I’m missing regarding the assigning the pins? Here’s just the snippet of code assigning the pins. Thanks for any help.

#include <AFMotor.h>
AF_Stepper motor(48, 2);

void setup() {
  Serial.begin(9600);           
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(11, INPUT);
  motor.setSpeed(500);   
}


void loop() {
  int btn_one = digitalRead(2);
  int btn_two = digitalRead(3);
  int btn_three = digitalRead(11);
}

Is there something fundamental I'm missing

The actual code. And some observations.

The AF_Stepper library makes assumptions about what pins you have your motor hooked up to. Perhaps there's a conflict?

Also, if you have the usual button hookup (button contact to ground) you will need to enable pull-up resistors on the I/O pins to read high when the button is not pushed, and low when pushed.

-- The Gadget Shield: accelerometer, RGB LED, IR transmit/receive, speaker, microphone, light sensor, potentiometer, pushbuttons

It just a snippet of the code. It does actually work. But I don't understand why I can't just say button 1 is 0 pin, button 2 is 1 pin etc etc. Why does splitting them up make it work?

@Rugged, I have the resistors etc. I think you've got it right thou, obviously the motor shield is using some of the pins so that's why they don't all work they're already in use. Thanks for the light shedding!

It just a snippet of the code. It does actually work.

How can you say that? Do you have some kind of in-circuit debugger?

But I don’t understand why I can’t just say button 1 is 0 pin, button 2 is 1 pin etc etc

Using pins 0 & 1 is a bit problematic because they are also connected to the serial lines of the UART interface but apart from that you can assign buttons to any pins.

Why does splitting them up make it work?

I don’t know, it shouldn’t and it doesn’t. Try removing the #include <AFMotor.h> to see if that is messing things up.

AWOL:

It just a snippet of the code. It does actually work.

How can you say that? Do you have some kind of in-circuit debugger?

No I just cut out all the gibberish to show you the part that was assigning the pins and then assigning the variable. It appears to be that a certain number of pins are used by the Motorshield, as lots of them do work fine but others don't at all and stop everything. I have it working fine now with 2,3 an 10,11.

Thanks for the info re-buttons 0 and 1 that was going to be my next question why don't the tutorials for DigitalRead start by using button 0?