hello everyone and i hope every ones haning a good night, i have this problem with my code let me explain what im trying to do first i want to use a snes contoler to send midi on notes to the computer via serial when a selected button eg. "A" "B" is pressed down and a midi off signal when the button is released however i only need one message sent when i hold down a button so i was trying to getr a if (buttonState != lastButtonState) type of thing going but im having a lot of trouble getting each button to send the notes here is my code so far
#include
SNESpad nintendo = SNESpad(2,3,4);
int buttonState = LOW;
int lastButtonState = LOW;
int state = 0;
int noteON = 144;//144 = 10010000 in binary, note on command
int noteOFF = 128;//128 = 10000000 in binary, note off command
void setup() {
Serial.begin(115200);
}
void loop() {
state = nintendo.buttons();
buttonState = (state);
if (buttonState != lastButtonState) {
if (state & SNES_B == 256 ) {
MIDImessage(noteON, 50);
}
else {
MIDImessage(noteOFF, 50);
}
lastButtonState = buttonState;
}
}
//send MIDI message
void MIDImessage(int command, int MIDInote) {
Serial.write(command);//send note on or note off command
Serial.write(MIDInote);//send pitch data
Serial.write(100);//send velocity data
}
thank you in advance for all your help