Arduino Mega 2560 I/O pin Problem

Hi,

I am trying to use pins 51 through 53 (on an Arduino Mega 2560) as digital inputs, however the program does not work when doing so. It works when I use pins before that (like 50, 49, etc.) but those particular pins do not work (the program does not run, or freezes). I don't really have an option to switch pins because as of now I am using the others as digital inputs/outputs already. If anyone knows what my problem could be, please let me know. Thanks!

however the program does not work when doing so

I don't see a program.

My program is very long, and since it works as expected when I switch the input pin from 51 to 49 I do not find as much error with my code as with the application of the I/O pin. I am certain that the pin is not declared as an input/output anywhere else in the code. If this is more of a different forum topic, I can ask somewhere else. Below I've written how I've used the pin if there is some mistake. Also, I forgot to mention I have a ethernet shield attached to this, but it is not attached to 51, but plugged in on top (and is working).

#define trigger   51

void setup() {
   pinMode(trigger, OUTPUT);
}

void loop() {
   if (trigger == 1) {
      selection = digitalRead(37);
   }
   else {
      selection = prevSelection;
   }
}

HOKIE_EE:
I am trying to use pins 51 through 53 (on an Arduino Mega 2560) as digital inputs, however the program does not work when doing so.

Those pins are for the SPI bus. You may have another device already on the bus causing conflict. An ethernet shield for instance using the same bus via the 6-pin ICSP cluster.

FYI, you can use analog pins as digital pins. Their pin numbers are A0-A15 are D54-D69. You can also use hardware serial port pins if you modify the arduino core. Are you trying to use interrupt on pins? Analog pins should do that.

HOKIE_EE: I am certain that the pin is not declared as an input/output anywhere else in the code. .....

I have a ethernet shield attached to this, but it is not attached to 51, but plugged in on top (and is working).

Well, you'd be wrong then.

Those are the SPI pins so the Ethernet shield is using them. It's just connecting through the ICSP header and not to the pin outs on the side of the board where you are expecting it.

#define trigger   51

void setup() {
   pinMode(trigger, OUTPUT);
}

void loop() {
   if (trigger == 1) {

Excuse me for butting in, but would you please explain how trigger can possibly ever be 1?