Gouda, Netherlands
Offline
Newbie
Karma: 0
Posts: 7
wat een ander niet wil dat geschiedt, doe dat snel voordat ie het ziet
|
 |
« Reply #2 on: March 30, 2012, 04:41:30 am » |
ok, here's what i got so far, the buttons on pin 0,22,21 and 37 are not working like the others, but as said, i want to get them to work as 4 bank recalls of the other 16 buttons, i really don't have any programming experience so i'm stuck....
#include <MIDI.h>
/* 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, 4); // 5 = 5 ms debounce time Bounce button2 = Bounce(2, 4); // which is appropriate for good Bounce button3 = Bounce(3, 4); // quality mechanical pushbuttons Bounce button4 = Bounce(4, 4); Bounce button5 = Bounce(5, 4); // if a button is too "sensitive" Bounce button6 = Bounce(6, 4); // to rapid touch, you can Bounce button7 = Bounce(7, 4); // increase this time. Bounce button8 = Bounce(8, 4); Bounce button9 = Bounce(9, 4); Bounce button10 = Bounce(10, 4); Bounce button11 = Bounce(11, 4); Bounce button12 = Bounce(12, 4); Bounce button13 = Bounce(13, 4); Bounce button14 = Bounce(14, 4); Bounce button15 = Bounce(15, 4); Bounce button16 = Bounce(16, 4); Bounce button17 = Bounce(17, 4); Bounce button18 = Bounce(18, 4); Bounce button19 = Bounce(19, 4); Bounce button20 = Bounce(20, 4);
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(37, INPUT_PULLUP); pinMode(1, INPUT_PULLUP); pinMode(2, INPUT_PULLUP); pinMode(3, INPUT_PULLUP); 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); pinMode(12, INPUT_PULLUP); pinMode(13, INPUT_PULLUP); pinMode(17, INPUT_PULLUP); pinMode(0, INPUT_PULLUP); pinMode(22, INPUT_PULLUP); pinMode(21, INPUT_PULLUP); pinMode(20, INPUT_PULLUP); pinMode(19, INPUT_PULLUP); pinMode(18, 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(); button17.update(); button18.update(); button19.update(); button20.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(27, 99, channel); // 27 = D#1 } if (button2.fallingEdge()) { usbMIDI.sendNoteOn(28, 99, channel); // 28 = E1 } if (button3.fallingEdge()) { usbMIDI.sendNoteOn(29, 99, channel); // 29 = F1 } if (button4.fallingEdge()) { usbMIDI.sendNoteOn(30, 99, channel); // 30 = F#1 } if (button5.fallingEdge()) { usbMIDI.sendNoteOn(31, 99, channel); // 31 = G1 } if (button6.fallingEdge()) { usbMIDI.sendNoteOn(32, 99, channel); // 32 = G#1 } if (button7.fallingEdge()) { usbMIDI.sendNoteOn(33, 99, channel); // 33 = A1 } if (button8.fallingEdge()) { usbMIDI.sendNoteOn(34, 99, channel); // 34 = A#1 } if (button9.fallingEdge()) { usbMIDI.sendNoteOn(35, 99, channel); // 35 = B1 } if (button10.fallingEdge()) { usbMIDI.sendNoteOn(36, 99, channel); // 36 = C2 } if (button11.fallingEdge()) { usbMIDI.sendNoteOn(37, 99, channel); // 37 = C#2 } if (button12.fallingEdge()) { usbMIDI.sendNoteOn(38, 99, channel); // 38 = D2 } if (button13.fallingEdge()) { usbMIDI.sendNoteOn(39, 99, channel); // 39 = D#2 } if (button14.fallingEdge()) { usbMIDI.sendNoteOn(40, 99, channel); // 40 = E2 } if (button15.fallingEdge()) { usbMIDI.sendNoteOn(41, 99, channel); // 41 = F2 } if (button16.fallingEdge()) { usbMIDI.sendNoteOn(42, 99, channel); // 42 = F#2 } if (button17.fallingEdge()) { usbMIDI.sendNoteOn(43, 99, channel); // 43 = G2 } if (button18.fallingEdge()) { usbMIDI.sendNoteOn(44, 99, channel); // 44 = G#2 } if (button19.fallingEdge()) { usbMIDI.sendNoteOn(45, 99, channel); // 45 = A2 } if (button20.fallingEdge()) { usbMIDI.sendNoteOn(46, 99, channel); // 46 = A#2 } // Check each button for "rising" edge // Send a MIDI Note Off message when each button releases // For many types of projects, you only care when the button // is pressed and the release isn't needed. // rising = low (pressed - button connects pin to ground) // to high (not pressed - voltage from pullup resistor) if (button1.risingEdge()) { usbMIDI.sendNoteOff(27, 0, channel); // 27 = D#1 } if (button2.risingEdge()) { usbMIDI.sendNoteOn(28, 0, channel); // 28 = E1 } if (button3.risingEdge()) { usbMIDI.sendNoteOn(29, 0, channel); // 29 = F1 } if (button4.risingEdge()) { usbMIDI.sendNoteOn(30, 0, channel); // 30 = F#1 } if (button5.risingEdge()) { usbMIDI.sendNoteOn(31, 0, channel); // 31 = G1 } if (button6.risingEdge()) { usbMIDI.sendNoteOn(32, 0, channel); // 32 = G#1 } if (button7.risingEdge()) { usbMIDI.sendNoteOn(33, 0, channel); // 33 = A1 } if (button8.risingEdge()) { usbMIDI.sendNoteOn(34, 0, channel); // 34 = A#1 } if (button9.risingEdge()) { usbMIDI.sendNoteOn(35, 0, channel); // 35 = B1 } if (button10.risingEdge()) { usbMIDI.sendNoteOn(36, 0, channel); // 36 = C2 } if (button11.risingEdge()) { usbMIDI.sendNoteOn(37, 0, channel); // 37 = C#2 } if (button12.risingEdge()) { usbMIDI.sendNoteOn(38, 0, channel); // 38 = D2 } if (button13.risingEdge()) { usbMIDI.sendNoteOn(39, 0, channel); // 39 = D#2 } if (button14.risingEdge()) { usbMIDI.sendNoteOn(40, 0, channel); // 40 = E2 } if (button15.risingEdge()) { usbMIDI.sendNoteOn(41, 0, channel); // 41 = F2 } if (button16.risingEdge()) { usbMIDI.sendNoteOn(42, 0, channel); // 42 = F#2 } if (button17.risingEdge()) { usbMIDI.sendNoteOn(43, 0, channel); // 43 = G2 } if (button18.risingEdge()) { usbMIDI.sendNoteOn(44, 0, channel); // 44 = G#2 } if (button19.risingEdge()) { usbMIDI.sendNoteOn(45, 0, channel); // 45 = A2 } if (button20.risingEdge()) { usbMIDI.sendNoteOn(46, 0, channel); // 46 = A#2 } }
|