hi there,
I'm working on a project with 16 arcadebuttons, they have to trigger note on and note off messages. I've done some programming and it works the way i want it to work, except for button 6, soldered to pin 10. I've tried some other pins but no succes... Can someone see a mistake in my coding? By default there was a button 0, is that of any importance? Any help would be appreciated!
greetings, patrick
/* Buttons to USB MIDI Example
You must select MIDI from the "Tools > USB Type" menu
This example code is in the public domain.
*/
#include <Bounce.h>
// the MIDI channel number to send messages
const int channel = 13;
// Create Bounce objects for each button. The Bounce object
// automatically deals with contact chatter or "bounce", and
// it makes detecting changes very simple.
Bounce button1 = Bounce(1, 8); // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 8); // which is appropriate for good
Bounce button3 = Bounce(3, 8); // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 8);
Bounce button5 = Bounce(5, 8); // if a button is too "sensitive"
Bounce button6 = Bounce(6, 8); // to rapid touch, you can
Bounce button7 = Bounce(7, 8); // increase this time.
Bounce button8 = Bounce(8, 8);
Bounce button9 = Bounce(9, 8);
Bounce button10 = Bounce(10, 8);
Bounce button11 = Bounce(11, 8);
Bounce button12 = Bounce(12, 8);
Bounce button13 = Bounce(13, 8);
Bounce button14 = Bounce(14, 8);
Bounce button15 = Bounce(15, 8);
Bounce button16 = Bounce(16, 8);
void setup() {
// Configure the pins for input mode with pullup resistors.
// The pushbuttons connect from each pin to ground. When
// the button is pressed, the pin reads LOW because the button
// shorts it to ground. When released, the pin reads HIGH
// because the pullup resistor connects to +5 volts inside
// the chip. LOW for "on", and HIGH for "off" may seem
// backwards, but using the on-chip pullup resistors is very
// convenient. The scheme is called "active low", and it's
// very commonly used in electronics... so much that the chip
// has built-in pullup resistors!
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP); // Teensy++ LED, may need 1k resistor pullup
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
}
void loop() {
// Update all the buttons. There should not be any long
// delays in loop(), so this runs repetitively at a rate
// faster than the buttons could be pressed and released.
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
button8.update();
button9.update();
button10.update();
button11.update();
button12.update();
button13.update();
button14.update();
button15.update();
button16.update();
// Check each button for "falling" edge.
// Send a MIDI Note On message when each button presses
// Update the Joystick buttons only upon changes.
// falling = high (not pressed - voltage from pullup resistor)
// to low (pressed - button connects pin to ground)
if (button1.fallingEdge()) {
usbMIDI.sendNoteOn(48, 99, channel); // 61 = C#4
}
if (button2.fallingEdge()) {
usbMIDI.sendNoteOn(49, 99, channel); // 62 = D4
}
if (button3.fallingEdge()) {
usbMIDI.sendNoteOn(50, 99, channel); // 63 = D#4
}
if (button4.fallingEdge()) {
usbMIDI.sendNoteOn(51, 99, channel); // 64 = E4
}
if (button5.fallingEdge()) {
usbMIDI.sendNoteOn(44, 99, channel); // 65 = F4
}
if (button6.fallingEdge()) {
usbMIDI.sendNoteOn(45, 99, channel); // 66 = F#4
}
if (button7.fallingEdge()) {
usbMIDI.sendNoteOn(46, 99, channel); // 67 = G4
}
if (button8.fallingEdge()) {
usbMIDI.sendNoteOn(47, 99, channel); // 68 = G#4
}
if (button9.fallingEdge()) {
usbMIDI.sendNoteOn(40, 99, channel); // 69 = A5
}
if (button10.fallingEdge()) {
usbMIDI.sendNoteOn(41, 99, channel); // 70 = A#5
}
if (button11.fallingEdge()) {
usbMIDI.sendNoteOn(42, 99, channel); // 71 = B5
}
if (button12.fallingEdge()) {
usbMIDI.sendNoteOn(43, 99, channel); // 71 = B5
}
if (button13.fallingEdge()) {
usbMIDI.sendNoteOn(36, 99, channel); // 71 = B5
}
if (button14.fallingEdge()) {
usbMIDI.sendNoteOn(37, 99, channel); // 71 = B5
}
if (button15.fallingEdge()) {
usbMIDI.sendNoteOn(38, 99, channel); // 71 = B5
}
if (button16.fallingEdge()) {
usbMIDI.sendNoteOn(39, 99, channel); // 71 = B5
}
if (button1.risingEdge()) {
usbMIDI.sendNoteOff(48, 0, channel); // 61 = C#4
}
if (button2.risingEdge()) {
usbMIDI.sendNoteOff(49, 0, channel); // 62 = D4
}
if (button3.risingEdge()) {
usbMIDI.sendNoteOff(50, 0, channel); // 63 = D#4
}
if (button4.risingEdge()) {
usbMIDI.sendNoteOff(51, 0, channel); // 64 = E4
}
if (button5.risingEdge()) {
usbMIDI.sendNoteOff(44, 0, channel); // 65 = F4
}
if (button6.risingEdge()) {
usbMIDI.sendNoteOff(45, 0, channel); // 66 = F#4
}
if (button7.risingEdge()) {
usbMIDI.sendNoteOff(46, 0, channel); // 67 = G4
}
if (button8.risingEdge()) {
usbMIDI.sendNoteOff(47, 0, channel); // 68 = G#4
}
if (button9.risingEdge()) {
usbMIDI.sendNoteOff(40, 0, channel); // 69 = A5
}
if (button10.risingEdge()) {
usbMIDI.sendNoteOff(41, 0, channel); // 70 = A#5
}
if (button11.risingEdge()) {
usbMIDI.sendNoteOff(42, 0, channel); // 71 = B5
}
if (button12.risingEdge()) {
usbMIDI.sendNoteOff(43, 0, channel); // 71 = B5
}
if (button13.risingEdge()) {
usbMIDI.sendNoteOff(36, 0, channel); // 71 = B5
}
if (button14.risingEdge()) {
usbMIDI.sendNoteOff(37, 0, channel); // 71 = B5
}
if (button15.risingEdge()) {
usbMIDI.sendNoteOff(38, 0, channel); // 71 = B5
}
if (button16.risingEdge()) {
usbMIDI.sendNoteOff(39, 0, channel); // 71 = B5
}
}