这是一个非常初级的问题。我需要一些关于如何将这两个草图合并为一个的指导。我对 Arduino 语言只有一些非常初级的知识。
我已经成功地独立测试了这两个草图,我现在只需要以某种方式将它们编译在一起。
任何帮助或指导将不胜感激!谢谢提前!
草图一:
// 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);
}
}
草图2:
int previous;
int current;
void setup() {
}
void loop () {
current = map(analogRead(11), 136, 1023, 0 , 127);
usbMIDI.sendControlChange(7, current, 1);
delay(5);
}