I followed this guide to load Hoodloader2 onto my Mega2560 to make a gamepad. All I did was add extra buttons to the original Sketch. Everything works but instead of it waiting for a button to be pressed, all of the inputs are looping in the Serial monitor. Here's my code:
const int Button1 = 1;
const int Button2 = 2;
const int Button3 = 3;
const int Button4 = 4;
const int UpButton = 7;
const int DownButton = 5;
const int LeftButton = 8;
const int RightButton = 6;
void setup(){
Serial.begin(9600);
pinMode(UpButton, INPUT);
pinMode(UpButton, INPUT);
pinMode(LeftButton, INPUT);
pinMode(RightButton, INPUT);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
pinMode(Button4, INPUT);
}
void loop(){
if(digitalRead(UpButton) == HIGH){
Serial.println("Up:");
delay(100);
}
else
if(digitalRead(UpButton) == LOW) {
delay(100);
}
if(digitalRead(DownButton) == HIGH){
Serial.println("Down:");
delay(100);
}
else
if(digitalRead(DownButton) == LOW) {
delay(100);
}
if(digitalRead(LeftButton) == HIGH){
Serial.println("Left:");
delay(100);
}
else
if(digitalRead(LeftButton) == LOW) {
delay(100);
}
if(digitalRead(RightButton) == HIGH){
Serial.println("Right:");
delay(100);
}
else
if(digitalRead(RightButton) == LOW) {
delay(100);
}
if(digitalRead(Button1) == HIGH){
Serial.println("Button1:");
delay(100);
}
else
if(digitalRead(Button1) == LOW) {
delay(100);
}
if(digitalRead(Button2) == HIGH){
Serial.println("Button2:");
delay(100);
}
else
if(digitalRead(Button2) == LOW) {
delay(100);
}
if(digitalRead(Button3) == HIGH){
Serial.println("Button3:");
delay(100);
}
else
if(digitalRead(Button3) == LOW) {
delay(100);
}
if(digitalRead(Button4) == HIGH){
Serial.println("Button4:");
delay(100);
}
else
if(digitalRead(Button4) == LOW) {
delay(100);
}
}
I added a picture of the Serial Monitor because I feel like I'm explaining it badly. Thanks.
Edit: I forgot to mention, I added the digitalRead(xxx) == LOW) to try and fix it but it didn't work.
