So I developed an application for an arduino uno that uses an IteadStudio Joystick Shield with 7 buttons and a joystick with an x/y movement tracker. The 7 buttons are connected to pins 3 through 9, and the joystick is connected to analog inputs 0 and 1, with 0 being the Y and 1 being the X. When I test the buttons, it works correctly. However, if I test the Analog inputs with the code below, the Serial monitor goes completely crazy, producing tons of random ascii characters and those letters with the dots above them. It produces these so fast that if I trigger a button, the serial message doesn't appear until about 5 seconds later.
Code:
int XValue;
int YValue;
void setup() {
pinMode(3, INPUT);
pinMode(4, INPUT);
pinMode(5, INPUT);
pinMode(6, INPUT);
pinMode(7, INPUT);
pinMode(8, INPUT);
pinMode(9, INPUT);
Serial.begin(9600);
}
void loop() {
if (digitalRead(3) == LOW) {
Serial.println("Digital pin 3 is LOW");
} else if (digitalRead(4) == LOW) {
Serial.println("Digital pin 4 is LOW");
} else if (digitalRead(5) == LOW) {
Serial.println("Digital pin 5 is LOW");
} else if (digitalRead(6) == LOW) {
Serial.println("Digital pin 6 is LOW");
} else if (digitalRead(7) == LOW) {
Serial.println("Digital pin 7 is LOW");
} else if (digitalRead(8) == LOW) {
Serial.println("Digital pin 8 is LOW");
} else if (digitalRead(9) == LOW) {
Serial.println("Digital pin 9 is LOW");
}
YValue = analogRead(A0);
XValue = analogRead(A1);
Serial.println("X=" + XValue);
Serial.println("Y=" + YValue);
}