Hi heres my code I'm using if it helps.
#include <Bounce.h>
const int channel = 1;
Bounce button1 = Bounce(16, 5);
Bounce button2 = Bounce(20, 5);
Bounce button3 = Bounce(0, 5);
Bounce button4 = Bounce(4, 5);
Bounce button5 = Bounce(15, 5);
Bounce button6 = Bounce(19, 5);
Bounce button7 = Bounce(1, 5);
Bounce button8 = Bounce(5, 5);
Bounce button9 = Bounce(14, 5);
Bounce button10 = Bounce(18, 5);
Bounce button11 = Bounce(2, 5);
Bounce button12 = Bounce(6, 5);
Bounce button13 = Bounce(13, 5);
Bounce button14 = Bounce(17, 5);
Bounce button15 = Bounce(3, 5);
Bounce button16 = Bounce(7, 5);
Bounce button17 = Bounce(24, 5);
Bounce button18 = Bounce(11, 5);
Bounce button19 = Bounce(12, 5);
Bounce button20 = Bounce(23, 5);
Bounce button21 = Bounce(10, 5);
Bounce button22 = Bounce(9, 5);
void setup() {
pinMode(0, INPUT_PULLUP);
pinMode(1, INPUT_PULLUP);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(7, INPUT_PULLUP);
pinMode(9, INPUT_PULLUP);
pinMode(10, INPUT_PULLUP);
pinMode(11, INPUT_PULLUP);
pinMode(12, INPUT_PULLUP);
pinMode(13, INPUT_PULLUP);
pinMode(14, INPUT_PULLUP);
pinMode(15, INPUT_PULLUP);
pinMode(16, INPUT_PULLUP);
pinMode(17, INPUT_PULLUP);
pinMode(18, INPUT_PULLUP);
pinMode(19, INPUT_PULLUP);
pinMode(20, INPUT_PULLUP);
pinMode(23, INPUT_PULLUP);
pinMode(24, INPUT_PULLUP);
}
void loop() {
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();
button21.update();
button22.update();
if (button1.fallingEdge()) {
usbMIDI.sendNoteOn(81, 99, channel); // 61 = C#4
}
if (button2.fallingEdge()) {
usbMIDI.sendNoteOn(80, 99, channel); // 62 = D4
}
if (button3.fallingEdge()) {
usbMIDI.sendNoteOn(79, 99, channel); // 63 = D#4
}
if (button4.fallingEdge()) {
usbMIDI.sendNoteOn(78, 99, channel); // 64 = E4
}
if (button5.fallingEdge()) {
usbMIDI.sendNoteOn(77, 99, channel); // 65 = F4
}
if (button6.fallingEdge()) {
usbMIDI.sendNoteOn(76, 99, channel); // 66 = F#4
}
if (button7.fallingEdge()) {
usbMIDI.sendNoteOn(75, 99, channel); // 67 = G4
}
if (button8.fallingEdge()) {
usbMIDI.sendNoteOn(74, 99, channel); // 68 = G#4
}
if (button9.fallingEdge()) {
usbMIDI.sendNoteOn(73, 99, channel); // 69 = A5
}
if (button10.fallingEdge()) {
usbMIDI.sendNoteOn(72, 99, channel); // 70 = A#5
}
if (button11.fallingEdge()) {
usbMIDI.sendNoteOn(71, 99, channel); // 71 = B5
}
if (button12.fallingEdge()) {
usbMIDI.sendNoteOn(70, 99, channel); // 71 = B5
}
if (button13.fallingEdge()) {
usbMIDI.sendNoteOn(69, 99, channel); // 71 = B5
}
if (button14.fallingEdge()) {
usbMIDI.sendNoteOn(68, 99, channel); // 71 = B5
}
if (button15.fallingEdge()) {
usbMIDI.sendNoteOn(67, 99, channel); // 71 = B5
}
if (button16.fallingEdge()) {
usbMIDI.sendNoteOn(66, 99, channel); // 71 = B5
}
if (button17.fallingEdge()) {
usbMIDI.sendNoteOn(65, 99, channel); // 71 = B5
}
if (button18.fallingEdge()) {
usbMIDI.sendNoteOn(64, 99, channel); // 71 = B5
}
if (button19.fallingEdge()) {
usbMIDI.sendNoteOn(63, 99, channel); // 71 = B5
}
if (button20.fallingEdge()) {
usbMIDI.sendNoteOn(62, 99, channel); // 71 = B5
}
if (button21.fallingEdge()) {
usbMIDI.sendNoteOn(61, 99, channel); // 71 = B5
}
if (button22.fallingEdge()) {
usbMIDI.sendNoteOn(60, 99, channel); // 71 = B5
}
if (button1.risingEdge()) {
usbMIDI.sendNoteOff(81, 0, channel); // 61 = C#4
}
if (button2.risingEdge()) {
usbMIDI.sendNoteOff(80, 0, channel); // 62 = D4
}
if (button3.risingEdge()) {
usbMIDI.sendNoteOff(79, 0, channel); // 63 = D#4
}
if (button4.risingEdge()) {
usbMIDI.sendNoteOff(78, 0, channel); // 64 = E4
}
if (button5.risingEdge()) {
usbMIDI.sendNoteOff(77, 0, channel); // 65 = F4
}
if (button6.risingEdge()) {
usbMIDI.sendNoteOff(76, 0, channel); // 66 = F#4
}
if (button7.risingEdge()) {
usbMIDI.sendNoteOff(75, 0, channel); // 67 = G4
}
if (button8.risingEdge()) {
usbMIDI.sendNoteOff(74, 0, channel); // 68 = G#4
}
if (button9.risingEdge()) {
usbMIDI.sendNoteOff(73, 0, channel); // 69 = A5
}
if (button10.risingEdge()) {
usbMIDI.sendNoteOff(72, 0, channel); // 70 = A#5
}
if (button11.risingEdge()) {
usbMIDI.sendNoteOff(71, 0, channel); // 71 = B5
}
if (button12.risingEdge()) {
usbMIDI.sendNoteOff(70, 0, channel); // 71 = B5
}
if (button13.risingEdge()) {
usbMIDI.sendNoteOff(69, 0, channel); // 71 = B5
}
if (button14.risingEdge()) {
usbMIDI.sendNoteOff(68, 0, channel); // 71 = B5
}
if (button15.risingEdge()) {
usbMIDI.sendNoteOff(67, 0, channel); // 71 = B5
}
if (button16.risingEdge()) {
usbMIDI.sendNoteOff(66, 0, channel); // 71 = B5
}
if (button17.risingEdge()) {
usbMIDI.sendNoteOff(65, 0, channel); // 71 = B5
}
if (button18.risingEdge()) {
usbMIDI.sendNoteOff(64, 0, channel); // 71 = B5
}
if (button19.risingEdge()) {
usbMIDI.sendNoteOff(63, 0, channel); // 71 = B5
}
if (button20.risingEdge()) {
usbMIDI.sendNoteOff(62, 0, channel); // 71 = B5
}
if (button21.risingEdge()) {
usbMIDI.sendNoteOff(61, 0, channel); // 71 = B5
}
if (button22.risingEdge()) {
usbMIDI.sendNoteOff(60, 0, channel); // 71 = B5
}
while (usbMIDI.read()) {
}
}
Im now adding neopixels in the mix, would these be easy to code in?
I'm wanting to light up random colours each time a button is pressed, is this possible?