Here's the code in my current project:
Maybe someone could put me in the right direction of how to adapt it with the bounce library..
/*
Midi button controller
8 Buttons send 8 different midi messages on CH0
Created March 2012
by Andrew Kirkby <http://www.kirkbysound.co.uk>
*/
//Constants to set pin numbers
const int buttonPin1 = 2; //pushbutton 1
const int buttonPin2 = 3; //pushbutton 2
const int buttonPin3 = 4; //pushbutton 3
const int buttonPin4 = 5; //pushbutton 4
const int ledPin = 6; //setup string ledPin as output 6
//const int ledPin1 = 7; //setup string ledPin1 as output 7
int buttonState1 = 0; // Set variable for reading button status
int buttonState2 = 0; // Set variable for reading button status
int buttonState3 = 0; // Set variable for reading button status
int buttonState4 = 0; // Set variable for reading button status
int val1; //variables for checking button status
int val2;
int val3;
int val4;
// ########################################################################
void setup() {
// put your setup code here, to run once:
pinMode(ledPin, OUTPUT);
//pinMode(ledPin1, OUTPUT);
Serial.begin(31250); // Set Midi Baud Rate
// Initialize buttons as inputs
pinMode (buttonPin1, INPUT);
pinMode (buttonPin2, INPUT);
pinMode (buttonPin3, INPUT);
pinMode (buttonPin4, INPUT);
digitalWrite(ledPin, LOW);
long lastDebounceTime = 0; // the last time the output pin was toggled
long debounceDelay = 50; // the debounce time; increase if the output flickers
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
buttonState3 = digitalRead(buttonPin3);
buttonState4 = digitalRead(buttonPin4);
}
// ########################################################################
void loop() {
// put your main code here, to run repeatedly:
//midimsg(0x90,0x1E,0x45);
val1 = digitalRead(buttonPin1); // read input value and store it in val
val2 = digitalRead(buttonPin2);
val3 = digitalRead(buttonPin3);
val4 = digitalRead(buttonPin4);
if (val1 != buttonState1) { // the button state has changed!
if (val1 == HIGH) { // check if the button is pressed
midimsg(0x90,0x45,0x45);
} else { // the button is -not- pressed...
//digitalWrite(ledPin, LOW);
}
}
if (val2 != buttonState2) { // the button state has changed!
if (val2 == HIGH) { // check if the button is pressed
midimsg(0x90,0x40,0x45);
} else { // the button is -not- pressed...
//digitalWrite(ledPin, LOW);
}
}
if (val3 != buttonState3) { // the button state has changed!
if (val3 == HIGH) { // check if the button is pressed
midimsg(0x90,0x35,0x45);
} else { // the button is -not- pressed...
//digitalWrite(ledPin, LOW);
}
}
if (val4 != buttonState4) { // the button state has changed!
if (val4 == HIGH) { // check if the button is pressed
midimsg(0x90,0x30,0x45);
} else { // the button is -not- pressed...
//digitalWrite(ledPin, LOW);
}
}
buttonState1 = val1;
buttonState2 = val2;
buttonState3 = val3;
buttonState4 = val4;
}
// plays a MIDI note. Doesn't check to see that
// cmd is greater than 127, or that data values are less than 127:
void midimsg(int M1, int M2, int M3) {
Serial.write(M1);
Serial.write(M2);
Serial.write(M3);
}