Hello,
I am trying to do something very simple, to connect inline five buttons in order to control it after in BOME Midi Translator. I just need each button to release a different signal in my console.
I succeed to connect one button, but it does not work when there are five buttons.
Here is the code and the schema of the connection.
It doesn't work because when I open the console, I have random 1 to 5 number, as if I pressed all buttons without a break.
const int buttonPin1 = 13;
const int buttonPin2 = 12;
const int buttonPin3 = 10;
const int buttonPin4 = 9;
const int buttonPin5 = 8;
int buttonState1 = LOW;
int buttonState2 = LOW;
int buttonState3 = LOW;
int buttonState4 = LOW;
int buttonState5 = LOW;
void setup() {
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
pinMode(buttonPin3, INPUT);
pinMode(buttonPin4, INPUT);
pinMode(buttonPin5, INPUT);
Serial.begin(9600);
}
void loop() {
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
buttonState5 = digitalRead(buttonPin5);
if (buttonState1 == HIGH) {
Serial.write('1');
delay(300);
} else {
}
if (buttonState2 == HIGH) {
Serial.write('2');
delay(300);
} else {
}
if (buttonState3 == HIGH) {
Serial.write('3');
delay(300);
} else {
}
if (buttonState4 == HIGH) {
Serial.write('4');
delay(300);
} else {
}
if (buttonState5 == HIGH) {
Serial.write('5');
delay(300);
}
else {
}
}
