OK I did not notice that before:
In the Serial Monitor of the Arduino Software I see something like this when I press a button:
0+0+
I realized, that when I press the Button and hold it, it just sends that:
0+
and when releasing it sends another 0+.
Even if I set the latency very high and try to push/release as quick as i physically can, it gives
two 0+.
So it does send two commands.
How could that be fixed?
Even if I set the latency very high and try to push/release as quick as i physically can, it gives
two 0+.
Yes it will it has nothing to do with the latency. On a button being pushed it will send a note on message when it is released it will send a note off message. So no matter how quickly you press and release it then there will always be two messages.
To fix it simply don't send the note off message on release, but send it on the push of the button you want to act as a stop.
Ok thank you. So I changed the code in the loop:
void loop(){
for(int i =0; i<9; i++){
button = digitalRead(switchPin[i]);
if (button == HIGH && buttonLast[i] == LOW) {
sendNote(144,noteToSend[i],127);
sendNote(144,noteToSend[i],0);
buttonLast[i] = button;
}
if (button == LOW && buttonLast[i] == HIGH) {
buttonLast[i] = button;
}
}
delay (20);
And it works now! Great!
Lateny still remains a little problem, but it is good enough to be used though. If I fix it, I will give an update!
Move the delay into the scope of the if statements, so that it only gets triggered on a button detection not every time.