This is a very beginner level question. I need some guidance on how to merge these two sketches into one. I have only some very beginner level knowledge of Arduino language.
I have successfully tested both sketches independently, I just need to compile them together in some way now.
Any help or guidance would be appreciated! Thank you advance!
Sketch 1:
// stomp using usb midi
#include <Bounce.h>
// midi channel
int channel = 1;
Bounce button1 = Bounce(2, 5);
Bounce button2 = Bounce(4, 5);
Bounce button3 = Bounce(6, 5);
Bounce button4 = Bounce(8, 5);
void setup()
{
pinMode(2, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
}
void loop()
{
button1.update();
button2.update();
button3.update();
button4.update();
if (button1.fallingEdge())
{
usbMIDI.sendNoteOn(60, 99, channel); // 60 = C4
}
if (button2.fallingEdge())
{
usbMIDI.sendNoteOn(62, 99, channel); // 62 = D4
}
if (button3.fallingEdge())
{
usbMIDI.sendNoteOn(64, 99, channel); // 64 = E4
}
if (button4.fallingEdge())
{
usbMIDI.sendNoteOn(68, 99, channel); // 68 = F4
}
//Note On message when button is released
if (button1.risingEdge()) {
usbMIDI.sendNoteOff(60, 0, channel);
}
if (button2.risingEdge()) {
usbMIDI.sendNoteOff(62, 0, channel);
}
if (button3.risingEdge()) {
usbMIDI.sendNoteOff(64, 0, channel);
}
if (button4.risingEdge()) {
usbMIDI.sendNoteOff(68, 0, channel);
}
}
Sketch 2:
int previous;
int current;
void setup() {
}
void loop () {
current = map(analogRead(11), 136, 1023, 0 , 127);
usbMIDI.sendControlChange(7, current, 1);
delay(5);
}