-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFC_4_Button.ino
83 lines (65 loc) · 2.15 KB
/
FC_4_Button.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// 4 Switch Midi Foot Controller
// Based on a Line6 FB4 and Arduino Nano
#include <Bounce2.h>
#include <MIDI.h>
#include <elapsedMillis.h>
MIDI_CREATE_DEFAULT_INSTANCE();
// the MIDI channel number to send messages
const int channel = 1;
// 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(3, 20); // Footswitch ; 5 = 5 ms debounce time
Bounce button2 = Bounce(4, 20); // Footswitch; which is appropriate for good quality mechanical pushbuttons
Bounce button3 = Bounce(5, 20);
Bounce button4 = Bounce(6, 20);
// Midi CC Value for every button
const int button1_cc = 100;
const int button2_cc = 101;
const int button3_cc = 102;
const int button4_cc = 103;
int ledPin = 13;
void setup() {
pinMode(ledPin, OUTPUT);
digitalWrite(ledPin, HIGH);
digitalWrite(ledPin, LOW);
pinMode(3, INPUT_PULLUP);
pinMode(4, INPUT_PULLUP);
pinMode(5, INPUT_PULLUP);
pinMode(6, INPUT_PULLUP);
MIDI.begin();
}
void loop() {
//MIDI.read(); // USB MIDI receive
button1.update();
button2.update();
button3.update();
button4.update();
// Edge Falling: High to Low (Switch goes down, Open to Closed, because off input_pullup)
if (button1.fallingEdge()) {
MIDI.sendNoteOn(button1_cc, 127, channel);
}
if (button2.fallingEdge()) {
MIDI.sendNoteOn(button2_cc, 127, channel);
}
if (button3.fallingEdge()) {
MIDI.sendNoteOn(button3_cc, 127, channel);
}
if (button4.fallingEdge()) {
MIDI.sendNoteOn(button4_cc, 127, channel);
}
// Edge Rising: Low to High (Switch goes up, Closed to Open, because off input_pullup)
if (button1.risingEdge()) {
MIDI.sendNoteOff(button1_cc, 0, channel);
}
if (button2.risingEdge()) {
MIDI.sendNoteOff(button2_cc, 0, channel);
}
if (button3.risingEdge()) {
MIDI.sendNoteOff(button3_cc, 0, channel);
}
if (button4.risingEdge()) {
MIDI.sendNoteOff(button4_cc, 0, channel);
}
//while (usbMIDI.read()); // read and discard any incoming MIDI messages
}