I am trying to build a button box for my PC using a Duemilanove board and 12 momentary switches. This is my first attempt to program so I used an example and expanded it to the following code. It works fine when I plug in the USB and monitor it with the Serial Monitor. My problem comes with my games not seeing the button presses. I have been looking for a tutorial about using Arduino boards for games and found a few but I am missing something to make it recognizable to the PC.
int Button1 = 1;
int Button2 = 2;
int Button3 = 3;
int Button4 = 4;
int Button5 = 5;
int Button6 = 6;
int Button7 = 7;
int Button8 = 8;
int Button9 = 9;
int Button10 = 10;
int Button11 = 11;
int Button12 = 12;
// the setup routine runs once when you press reset:
void setup() {
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
// make the pushbutton's pin an input:
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
pinMode(Button4, INPUT);
pinMode(Button5, INPUT);
pinMode(Button6, INPUT);
pinMode(Button7, INPUT);
pinMode(Button8, INPUT);
pinMode(Button9, INPUT);
pinMode(Button10, INPUT);
pinMode(Button11, INPUT);
pinMode(Button12, INPUT);
}
// the loop routine runs over and over again forever:
void loop() {
// read the input pin:
int buttonState1 = digitalRead(Button1);
int buttonState2 = digitalRead(Button2);
int buttonState3 = digitalRead(Button3);
int buttonState4 = digitalRead(Button4);
int buttonState5 = digitalRead(Button5);
int buttonState6 = digitalRead(Button6);
int buttonState7 = digitalRead(Button7);
int buttonState8 = digitalRead(Button8);
int buttonState9 = digitalRead(Button9);
int buttonState10 = digitalRead(Button10);
int buttonState11 = digitalRead(Button11);
int buttonState12 = digitalRead(Button12);
// print out the state of the button:
Serial.println(buttonState1);
Serial.println(buttonState2);
Serial.println(buttonState3);
Serial.println(buttonState4);
Serial.println(buttonState5);
Serial.println(buttonState6);
Serial.println(buttonState7);
Serial.println(buttonState8);
Serial.println(buttonState9);
Serial.println(buttonState10);
Serial.println(buttonState11);
Serial.println(buttonState12);
delay(1); // delay in between reads for stability
}