forked from felixgasiaux/laser-harph
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathharph.ino
223 lines (210 loc) · 7.12 KB
/
harph.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
/* Buttons to USB MIDI Example
You must select MIDI from the "Tools > USB Type" menu
To view the raw MIDI data on Linux: aseqdump -p "Teensy MIDI"
This example code is in the public domain.
*/
#include <Bounce.h>
// 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 button0 = Bounce(0, 10);
Bounce button1 = Bounce(1, 10); // 5 = 5 ms debounce time
Bounce button2 = Bounce(2, 10); // which is appropriate for good
Bounce button3 = Bounce(3, 10); // quality mechanical pushbuttons
Bounce button4 = Bounce(4, 10);
Bounce button5 = Bounce(5, 10); // if a button is too "sensitive"
Bounce button6 = Bounce(6, 10); // to rapid touch, you can
Bounce button7 = Bounce(7, 10); // increase this time.
Bounce button8 = Bounce(8, 10);
Bounce button9 = Bounce(9, 10);
Bounce button10 = Bounce(10, 10);
Bounce button11 = Bounce(11, 10);
Bounce button12 = Bounce(12, 10);
// 13 is the LED
Bounce button14 = Bounce(14, 10);
void setup() {
// Configure the pins for INPUT mode with pullup resistors.
//For our project, the laser harph, use INPUT and connect the
// different pins on one hand to one of the inputs, from 0-13 and the other
// End TO GROUND
// Using this the diode should work as a button... I want to make clear SHOULD
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); // Teensy++ 2.0 LED, may need 1k resistor 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, OUTPUT); // 13 is the LED
pinMode(14, INPUT_PULLUP);
// flash LED 3 times to show that it has booted
digitalWrite(13, HIGH); // LED on
delay(500);
digitalWrite(13, LOW); // LED off
delay(500);
digitalWrite(13, HIGH); // LED on
delay(500);
digitalWrite(13, LOW); // LED off
delay(500);
digitalWrite(13, HIGH); // LED on
delay(500);
digitalWrite(13, LOW); // LED off
}
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.
button0.update();
button1.update();
button2.update();
button3.update();
button4.update();
button5.update();
button6.update();
button7.update();
button8.update();
button9.update();
button10.update();
button11.update();
button12.update();
// 13 is the LED
button14.update();
// Check each button for "rising" 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 (button0.risingEdge()) {
usbMIDI.sendNoteOn(48, 99, channel); // 48 = C4
digitalWrite(13, HIGH); // LED on
}
if (button1.risingEdge()) {
usbMIDI.sendNoteOn(50, 99, channel); // 50 = D4
digitalWrite(13, HIGH); // LED on
}
if (button2.risingEdge()) {
usbMIDI.sendNoteOn(52, 99, channel); // 52 = E4
digitalWrite(13, HIGH); // LED on
}
if (button3.risingEdge()) {
usbMIDI.sendNoteOn(53, 99, channel); // 53 = F4
digitalWrite(13, HIGH); // LED on
}
if (button4.risingEdge()) {
usbMIDI.sendNoteOn(55, 99, channel); // 55 = G4
digitalWrite(13, HIGH); // LED on
}
if (button5.risingEdge()) {
usbMIDI.sendNoteOn(57, 99, channel); // 57 = A4
digitalWrite(13, HIGH); // LED on
}
if (button6.risingEdge()) {
usbMIDI.sendNoteOn(59, 99, channel); // 59 = B4
digitalWrite(13, HIGH); // LED on
}
if (button7.risingEdge()) {
usbMIDI.sendNoteOn(60, 99, channel); // 60 = C5
digitalWrite(13, HIGH); // LED on
}
if (button8.risingEdge()) {
usbMIDI.sendNoteOn(62, 99, channel); // 62 = D5
digitalWrite(13, HIGH); // LED on
}
if (button9.risingEdge()) {
usbMIDI.sendNoteOn(64, 99, channel); // 64 = E5
digitalWrite(13, HIGH); // LED on
}
if (button10.risingEdge()) {
usbMIDI.sendNoteOn(65, 99, channel); // 65 = F5
digitalWrite(13, HIGH); // LED on
}
if (button11.risingEdge()) {
usbMIDI.sendNoteOn(67, 99, channel); // 67 = G5
digitalWrite(13, HIGH); // LED on
}
if (button12.risingEdge()) {
usbMIDI.sendNoteOn(69, 99, channel); // 69 = A5
digitalWrite(13, HIGH); // LED on
}
// 13 is the LED
if (button14.risingEdge()) {
usbMIDI.sendNoteOn(71, 99, channel); // 71 = B5
digitalWrite(13, HIGH); // LED on
}
// 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 (button0.fallingEdge()) {
usbMIDI.sendNoteOff(48, 99, channel); // 48 = C4
digitalWrite(13, LOW); // LED on
}
if (button1.fallingEdge()) {
usbMIDI.sendNoteOff(50, 99, channel); // 50 = D4
digitalWrite(13, LOW); // LED on
}
if (button2.fallingEdge()) {
usbMIDI.sendNoteOff(52, 99, channel); // 52 = E4
digitalWrite(13, LOW); // LED on
}
if (button3.fallingEdge()) {
usbMIDI.sendNoteOff(53, 99, channel); // 53 = F4
digitalWrite(13, LOW); // LED on
}
if (button4.fallingEdge()) {
usbMIDI.sendNoteOff(55, 99, channel); // 55 = G4
digitalWrite(13, LOW); // LED on
}
if (button5.fallingEdge()) {
usbMIDI.sendNoteOff(57, 99, channel); // 57 = A4
digitalWrite(13, LOW); // LED on
}
if (button6.fallingEdge()) {
usbMIDI.sendNoteOff(59, 99, channel); // 59 = B4
digitalWrite(13, LOW); // LED on
}
if (button7.fallingEdge()) {
usbMIDI.sendNoteOff(60, 99, channel); // 60 = C5
digitalWrite(13, LOW); // LED on
}
if (button8.fallingEdge()) {
usbMIDI.sendNoteOff(62, 99, channel); // 62 = D5
digitalWrite(13, LOW); // LED on
}
if (button9.fallingEdge()) {
usbMIDI.sendNoteOff(64, 99, channel); // 64 = E5
digitalWrite(13, LOW); // LED on
}
if (button10.fallingEdge()) {
usbMIDI.sendNoteOff(65, 99, channel); // 65 = F5
digitalWrite(13, LOW); // LED on
}
if (button11.fallingEdge()) {
usbMIDI.sendNoteOff(67, 99, channel); // 67 = G5
digitalWrite(13, LOW); // LED on
}
if (button12.fallingEdge()) {
usbMIDI.sendNoteOff(69, 99, channel); // 69 = A5
digitalWrite(13, LOW); // LED on
}
// 13 is the LED
if (button14.fallingEdge()) {
usbMIDI.sendNoteOff(71, 99, channel); // 71 = B5
digitalWrite(13, LOW); // LED on
}
// MIDI Controllers should discard incoming MIDI messages.
// http://forum.pjrc.com/threads/24179-Teensy-3-Ableton-Analog-CC-causes-midi-crash
while (usbMIDI.read()) {
// ignore incoming messages
}
}