Revision 1:b5bcad8e7803 CollidoscopeTeensy

View differences:

CollidoscopeTeensy/CollidoscopeTeensy_new.ino
1

  
2
/******************************************************************************
3

  
4
 *  Ben Bengler
5
 *  mail@benbengler.com
6
 *  02.05.2016
7
 *
8
 *  Collidoscope 
9
 *  
10
 *  Teensy 2 ++ pinout: https://www.pjrc.com/teensy/card4b.pdf
11
 *  
12
 *  ANALOG INPUTS:
13
 *  Wavejet   -> F0 (38) [Horizontal rail 1]
14
 *  Wavejet   -> F1 (39) [Horizontal rail 2]
15
 *  Filter 1  -> F2 (40) [Vertical rail 1]
16
 *  Filter 2  -> F4 (42) [Vertical rail 2] 
17
 *
18
 *  DIGITAL INPUTS [INTERRUPTS]:
19
 *  Sel. length 1  -> INT0/INT1 (0, 1)  [Encoder 1]
20
 *  Sel. length 2  -> INT2/INT3 (2, 3)  [Encoder 2]
21
 *  Duration 1     -> INT4/INT5 (36, 37)[Encoder 3] 
22
 *  Duration 2     -> INT6/INT7 (18, 19)[Encoder 4] 
23
 *
24
 *  DIGITAL INPUTS:
25
 *  Play1 toggle  -> B0 (20)
26
 *  Record1       -> B1 (21)
27
 *  Play2 toggle  -> B3 (22)
28
 *  Record2       -> B4 (24)
29
 *  
30
 *  DIGITAL OUTPUTS:
31
 *  Record Button 1 Led -> D4 (4)
32
 *  Record Button 2 Led -> D5 (5)
33

  
34
 ******************************************************************************/ 
35

  
36

  
37
#include <Encoder.h>
38
#include <Bounce.h>
39

  
40
///////////////////////////////////////////////////
41
//MIDI settings
42
const int midi_chan_inst1 = 1; // MIDI channel for Instrument 1
43
const int midi_chan_inst2 = 2; // MIDI channel for Instrument 2
44

  
45
const int cc_length = 1;    // MIDI cc controlling selection length
46
const int cc_duration = 2;  // MIDI cc controlling duration
47
const int cc_filter = 7;    // MIDI cc controlling LP filter
48
const int cc_play = 4;      // MIDI cc controlling PLAY
49
const int cc_record = 5;    // MIDI cc controlling RECORD
50
//const int cc_reset = 100; // MIDI cc controlling instrument RESET
51

  
52
///////////////////////////////////////////////////
53
//Default Values:
54
const int  Enc_def = 64; //default selection length  
55
int MIDI_led_state = LOW;
56
//boolean reset1 = true;
57
//boolean reset2 = true;
58

  
59
///////////////////////////////////////////////////
60
// Interface Inputs
61

  
62
//Buttons:
63

  
64
const int Pin_play1 = 20;       //B0    
65
const int Pin_record1 = 21;     //B1
66
const int Pin_play2 = 23;       //B3
67
const int Pin_record2 = 24;     //B4
68
const int Pin_record1_led =  4; //D4
69
const int Pin_record2_led =  5; //D5
70
const int Pin_MIDIled =  6;
71

  
72
//const int Pin_reset1 = 22;    //B2, not in use
73
//const int Pin_reset2 = 25;    //B5, not in use
74

  
75
Bounce button1 = Bounce(Pin_play1, 5); 
76
Bounce button2 = Bounce(Pin_record1, 5); 
77
Bounce button3 = Bounce(Pin_play2, 5); 
78
Bounce button4 = Bounce(Pin_record2, 5); 
79

  
80
 
81
//Encoder
82
Encoder Enc1 (0, 1);  //Encoder for section length on Wavejet 1
83
Encoder Enc2 (2, 3);  //Encoder for section length on Wavejet 2
84
Encoder Enc3 (36, 37);  //Encoder for duration of Wavejet 1 [granularisation effect]
85
Encoder Enc4 (18, 19);  //Encoder for duration of Wavejet 2 [granularisation effect]
86

  
87
// Variables
88
const int jitter_thresh = 10; //7threshold value for analog INs to suppress sending MIDI due to input jitter 
89
const int jitter_thresh_short = 5;
90

  
91
void setup() {  
92

  
93
pinMode(Pin_play1, INPUT_PULLUP); 
94
pinMode(Pin_record1, INPUT_PULLUP);
95
pinMode(Pin_play2, INPUT_PULLUP);
96
pinMode(Pin_record2, INPUT_PULLUP);
97

  
98

  
99
pinMode(Pin_MIDIled, OUTPUT); 
100
pinMode(Pin_record1_led, OUTPUT);
101
pinMode(Pin_record2_led, OUTPUT);
102
}
103

  
104
//Store recent values to detect parameter change
105
long Enc1_old = -999;
106
long Enc2_old = -999;
107
long Enc3_old = -999;
108
long Enc4_old = -999;
109

  
110
uint16_t Jet1_old = 0;
111
int16_t Jet1_old_MIDI = -1;
112
uint16_t Jet2_old = 0;
113
int16_t Jet2_old_MIDI = -1;
114
uint16_t filter1_old = 0;
115
int16_t filter1_old_MIDI = -1;
116
uint16_t filter2_old = 0;
117
int16_t filter2_old_MIDI = -1;
118

  
119
void loop() {
120

  
121
  digitalWrite(Pin_MIDIled, LOW);
122
  digitalWrite(Pin_record1_led, HIGH);
123
  digitalWrite(Pin_record2_led, HIGH);
124
  button1.update();
125
  button2.update();
126
  button3.update();
127
  button4.update();
128

  
129
  
130
  uint16_t Jet1_new = analogRead(0); //read Wavejet/Rail 1
131
  uint16_t Jet2_new = analogRead(1); //read Wavejet/Rail 2
132
  uint16_t filter1_new = analogRead(2);   //read filter Instrument 1; ADJUST INPUT RANGE ACCORDING TO SENSOR    
133
  uint16_t filter2_new = analogRead(4);   //read filter Instrument 2; ADJUST INPUT RANGE ACCORDING TO SENSOR  
134

  
135

  
136
  
137
  //Encoder 1 [Controls selection length of wave 1]
138
  long Enc1_new = Enc1.read();
139
  Enc1_new = constrain(Enc1_new, 0, 127); //constrain to 7-bit MIDI range
140
  
141
  //Dynamic reset of counter to MIDI range 
142
  if (Enc1_new <= 0){
143
    Enc1.write(0); 
144
  }
145
  else if (Enc1_new >= 127){
146
    Enc1.write(127); 
147
  }
148
     
149
  //Encoder 2 [Controls selection length of wave 2]
150
  long Enc2_new = Enc2.read();
151
  Enc2_new = constrain(Enc2_new, 0, 127); //constrain to 7-bit MIDI range
152
  
153
  //Dynamic reset of counter to MIDI range 
154
  if (Enc2_new <= 0){
155
    Enc2.write(0); 
156
  }
157
  else if (Enc2_new >= 127){
158
    Enc2.write(127); 
159
  }
160

  
161
  //Encoder 3 [Controls duration of wave 1]
162
  long Enc3_new = Enc3.read();
163
  Enc3_new = constrain(Enc3_new, 0, 127); //constrain to 7-bit MIDI range
164
  
165
  //Dynamic reset of counter to MIDI range 
166
  if (Enc3_new <= 0){
167
    Enc3.write(0); 
168
  }
169
  else if (Enc3_new >= 127){
170
    Enc3.write(127); 
171
  }
172

  
173
  //Encoder 4 [Controls duration of wave 2]
174
  long Enc4_new = Enc4.read();
175
  Enc4_new = constrain(Enc4_new, 0, 127); //constrain to 7-bit MIDI range
176
  
177
  //Dynamic reset of counter to MIDI range 
178
  if (Enc4_new <= 0){
179
    Enc4.write(0); 
180
  }
181
  else if (Enc4_new >= 127){
182
    Enc4.write(127); 
183
  }
184

  
185
 
186
 //Instrument 1 Controls//////////////////////////////////////  
187
 
188
 //Loop/Keymode Switch Instrument 1 
189
   
190
 if (button1.risingEdge()) {   
191
   //Serial.println("Loop mode");
192
   usbMIDI.sendControlChange(cc_play, 1, midi_chan_inst1);
193
 }
194
   
195
 if (button1.fallingEdge()) {   
196
   //Serial.println("Keyboardmode mode");
197
   usbMIDI.sendControlChange(cc_play, 0, midi_chan_inst1);
198
 }
199
     
200
   
201
 //Record Instrument 1
202
 if (button2.fallingEdge()) {   
203
   //Serial.println("RECORD! Instrument 1");
204
   usbMIDI.sendControlChange(cc_record, 1, midi_chan_inst1);
205
 }
206

  
207
 //send MIDI Wavejet 1 [Position Instrument 1]
208
 if (Jet1_new > Jet1_old+jitter_thresh || Jet1_new < Jet1_old-jitter_thresh) {
209
    
210
    int16_t midiVal = constrain( map(Jet1_new, 988, 121, 0, 149), 0, 149 );
211
    // int16_t midiVal = constrain( map( Jet1_new, 23, 928, 0, 149 ), 0, 149 ); old collidoscope 
212
    if( midiVal != Jet1_old_MIDI ){
213
      Jet1_old_MIDI = midiVal;
214
      usbMIDI.sendPitchBend( midiVal, midi_chan_inst1 );
215
    }
216

  
217
    Jet1_old = Jet1_new;
218
    digitalWrite(Pin_MIDIled, HIGH);
219
 }
220

  
221

  
222
 //send MIDI Filter 1 [Filter Instrument 1]
223

  
224
 if ( filter1_new > filter1_old+jitter_thresh_short || filter1_new < filter1_old-jitter_thresh_short ) {         // maybe adding jitter threshold needed, see Jet1_new  
225
 
226
    int16_t midiVal = constrain( map(filter1_new, 145, 756, 0, 127), 0, 127 );
227
    if( midiVal != filter1_old_MIDI){
228
      //Serial.println( midiVal );
229
      filter1_old_MIDI = midiVal;
230
      usbMIDI.sendControlChange(cc_filter, midiVal, midi_chan_inst1);
231
    }
232
    
233
    filter1_old = filter1_new;
234
    digitalWrite(Pin_MIDIled, HIGH);
235
  }
236

  
237
  //send MIDI Encoder 1 [Selection length Instrument 1]
238
  if (Enc1_new != Enc1_old) {
239
    Enc1_old = Enc1_new;
240
    //Serial.println("Encoder 1: ");
241
    //Serial.println(Enc1_new);
242
    usbMIDI.sendControlChange(cc_length, Enc1_new, midi_chan_inst1);
243
    digitalWrite(Pin_MIDIled, HIGH);
244
  }
245

  
246
  //send MIDI Encoder 3 [Duration Instrument 1]
247
  if (Enc3_new != Enc3_old) {
248
    Enc3_old = Enc3_new;
249
    //Serial.println("Encoder 3: ");
250
    //Serial.println(Enc3_new);
251
    usbMIDI.sendControlChange(cc_duration, Enc3_new, midi_chan_inst1);
252
    digitalWrite(Pin_MIDIled, HIGH);
253
  }
254
  
255
  
256
  //Instrument 2 Controls//////////////////////////////////////  
257
  
258
  //Loop/Keymode Switch Instrument 2
259
   
260
  if (button3.risingEdge()) {   
261
    //Serial.println("Loop mode");
262
    usbMIDI.sendControlChange(cc_play, 1, midi_chan_inst2);
263
  }
264
  
265
  if (button3.fallingEdge()) {   
266
    //Serial.println("Keyboardmode mode");
267
    usbMIDI.sendControlChange(cc_play, 0, midi_chan_inst2);
268
  }
269
  
270
  //Record Instrument 2
271
  if (button4.fallingEdge()) {   
272
    //Serial.println("RECORD! Instrument 2");
273
    usbMIDI.sendControlChange(cc_record, 1, midi_chan_inst2);
274
  }
275

  
276
  //send MIDI Wavejet 2 [Position Instrument 2]
277
  
278
  if (Jet2_new > Jet2_old+jitter_thresh || Jet2_new < Jet2_old-jitter_thresh) {
279
    //Serial.println("RECORD! Instrument 2");
280
    int16_t midiVal = constrain( map( Jet2_new, 109, 992, 149, 0 ), 0, 149 );
281
    if( midiVal != Jet2_old_MIDI ){
282
      Jet2_old_MIDI = midiVal;
283
      usbMIDI.sendPitchBend( midiVal, midi_chan_inst2 );
284
    }
285

  
286
    Jet2_old = Jet2_new;
287
    digitalWrite(Pin_MIDIled, HIGH);
288
  }
289
  
290
 //Serial.println(filter2_new);
291
   if ( filter2_new > filter2_old+jitter_thresh_short || filter2_new < filter2_old-jitter_thresh_short ) {         // maybe adding jitter threshold needed, see Jet1_new  
292
    int16_t midiVal = constrain( map(filter2_new, 132, 700, 0, 127), 0, 127 );
293
    if( midiVal != filter2_old_MIDI){
294
      //Serial.println( midiVal );
295
      filter2_old_MIDI = midiVal;
296
      usbMIDI.sendControlChange(cc_filter, midiVal, midi_chan_inst2);
297
    }
298
    
299
    filter2_old = filter2_new;
300
    digitalWrite(Pin_MIDIled, HIGH);
301
  }
302
   
303
  
304
  //send MIDI Encoder 2 [Selection length Instrument 2]
305
  if (Enc2_new != Enc2_old) {
306
    Enc2_old = Enc2_new;
307
    //Serial.println("Encoder 2: ");
308
    //Serial.println(Enc2_new);
309
    usbMIDI.sendControlChange(cc_length, Enc2_new, midi_chan_inst2);
310
    digitalWrite(Pin_MIDIled, HIGH);
311
  }
312

  
313
  //send MIDI Encoder 4 [Duration Instrument 2]
314
  if (Enc4_new != Enc4_old) {
315
    Enc4_old = Enc4_new;
316
    //Serial.println("Encoder 4: ");
317
    //Serial.println(Enc4_new);
318
    usbMIDI.sendControlChange(cc_duration, Enc4_new, midi_chan_inst2);
319
    digitalWrite(Pin_MIDIled, HIGH);
320
  }
321
    
322
}
323

  
CollidoscopeTeensy/CollidoscopeTeensy_original.ino
1

  
2
/******************************************************************************
3

  
4
 *  Ben Bengler
5
 *  mail@benbengler.com
6
 *  02.05.2016
7
 *
8
 *  Collidoscope 
9
 *  
10
 *  Teensy 2 ++ pinout: https://www.pjrc.com/teensy/card4b.pdf
11
 *  
12
 *  ANALOG INPUTS:
13
 *  Wavejet   -> F0 (38) [Horizontal rail 1]
14
 *  Wavejet   -> F1 (39) [Horizontal rail 2]
15
 *  Filter 1  -> F2 (40) [Vertical rail 1]
16
 *  Filter 2  -> F4 (42) [Vertical rail 2] 
17
 *
18
 *  DIGITAL INPUTS [INTERRUPTS]:
19
 *  Sel. length 1  -> INT0/INT1 (0, 1)  [Encoder 1]
20
 *  Sel. length 2  -> INT2/INT3 (2, 3)  [Encoder 2]
21
 *  Duration 1     -> INT4/INT5 (36, 37)[Encoder 3] 
22
 *  Duration 2     -> INT6/INT7 (18, 19)[Encoder 4] 
23
 *
24
 *  DIGITAL INPUTS:
25
 *  Play1 toggle  -> B0 (20)
26
 *  Record1       -> B1 (21)
27
 *  Play2 toggle  -> B3 (22)
28
 *  Record2       -> B4 (24)
29
 *  
30
 *  DIGITAL OUTPUTS:
31
 *  Record Button 1 Led -> D4 (4)
32
 *  Record Button 2 Led -> D5 (5)
33

  
34
 ******************************************************************************/ 
35

  
36

  
37
#include <Encoder.h>
38
#include <Bounce.h>
39

  
40
///////////////////////////////////////////////////
41
//MIDI settings
42
const int midi_chan_inst1 = 1; // MIDI channel for Instrument 1
43
const int midi_chan_inst2 = 2; // MIDI channel for Instrument 2
44

  
45
const int cc_length = 1;    // MIDI cc controlling selection length
46
const int cc_duration = 2;  // MIDI cc controlling duration
47
const int cc_filter = 7;    // MIDI cc controlling LP filter
48
const int cc_play = 4;      // MIDI cc controlling PLAY
49
const int cc_record = 5;    // MIDI cc controlling RECORD
50
//const int cc_reset = 100; // MIDI cc controlling instrument RESET
51

  
52
///////////////////////////////////////////////////
53
//Default Values:
54
const int  Enc_def = 64; //default selection length  
55
int MIDI_led_state = LOW;
56
//boolean reset1 = true;
57
//boolean reset2 = true;
58

  
59
///////////////////////////////////////////////////
60
// Interface Inputs
61

  
62
//Buttons:
63

  
64
const int Pin_play1 = 20;       //B0    
65
const int Pin_record1 = 21;     //B1
66
const int Pin_play2 = 23;       //B3
67
const int Pin_record2 = 24;     //B4
68
const int Pin_record1_led =  4; //D4
69
const int Pin_record2_led =  5; //D5
70
const int Pin_MIDIled =  6;
71

  
72
//const int Pin_reset1 = 22;    //B2, not in use
73
//const int Pin_reset2 = 25;    //B5, not in use
74

  
75
Bounce button1 = Bounce(Pin_play1, 5); 
76
Bounce button2 = Bounce(Pin_record1, 5); 
77
Bounce button3 = Bounce(Pin_play2, 5); 
78
Bounce button4 = Bounce(Pin_record2, 5); 
79

  
80
 
81
//Encoder
82
Encoder Enc1 (0, 1);  //Encoder for section length on Wavejet 1
83
Encoder Enc2 (2, 3);  //Encoder for section length on Wavejet 2
84

  
85

  
86
// Variables
87
const int jitter_thresh = 10; //7threshold value for analog INs to suppress sending MIDI due to input jitter 
88

  
89
void setup() {  
90

  
91
pinMode(Pin_play1, INPUT_PULLUP); 
92
pinMode(Pin_record1, INPUT_PULLUP);
93
pinMode(Pin_play2, INPUT_PULLUP);
94
pinMode(Pin_record2, INPUT_PULLUP);
95

  
96

  
97
pinMode(Pin_MIDIled, OUTPUT); 
98
pinMode(Pin_record1_led, OUTPUT);
99
pinMode(Pin_record2_led, OUTPUT);
100
}
101

  
102
//Store recent values to detect parameter change
103
long Enc1_old = -999;
104
long Enc2_old = -999;
105

  
106
uint16_t Jet1_old = 0;
107
int16_t Jet1_old_MIDI = -1;
108
uint16_t Jet2_old = 0;
109
int16_t Jet2_old_MIDI = -1;
110

  
111
uint16_t filter1_old = 0;
112
int16_t filter1_old_MIDI = -1;
113
uint16_t filter2_old = 0;
114
int16_t filter2_old_MIDI = -1;
115

  
116
uint16_t dur1_old = 0;
117
int16_t dur1_old_MIDI = -1;
118
uint16_t dur2_old = 0;
119
int16_t dur2_old_MIDI = -1;
120

  
121
void loop() {
122

  
123
  digitalWrite(Pin_MIDIled, LOW);
124
  digitalWrite(Pin_record1_led, HIGH);
125
  digitalWrite(Pin_record2_led, HIGH);
126
  button1.update();
127
  button2.update();
128
  button3.update();
129
  button4.update();
130

  
131
  
132
  uint16_t Jet1_new = analogRead(0); //read Wavejet/Rail 1
133
  uint16_t Jet2_new = analogRead(1); //read Wavejet/Rail 2
134
  uint16_t filter1_new = analogRead(2);   //read filter Instrument 1; ADJUST INPUT RANGE ACCORDING TO SENSOR    
135
  uint16_t filter2_new = analogRead(4);   //read filter Instrument 2; ADJUST INPUT RANGE ACCORDING TO SENSOR  
136
  uint16_t dur1_new = analogRead(3); 
137
  uint16_t dur2_new = analogRead(5);
138

  
139
  
140
  //Encoder 1 [Controls selection length of wave 1]
141
  long Enc1_new = Enc1.read();
142
  Enc1_new = constrain(Enc1_new, 0, 127); //constrain to 7-bit MIDI range
143
  
144
  //Dynamic reset of counter to MIDI range 
145
  if (Enc1_new <= 0){
146
    Enc1.write(0); 
147
  }
148
  else if (Enc1_new >= 127){
149
    Enc1.write(127); 
150
  }
151
     
152
  //Encoder 2 [Controls selection length of wave 2]
153
  long Enc2_new = Enc2.read();
154
  Enc2_new = constrain(Enc2_new, 0, 127); //constrain to 7-bit MIDI range
155
  
156
  //Dynamic reset of counter to MIDI range 
157
  if (Enc2_new <= 0){
158
    Enc2.write(0); 
159
  }
160
  else if (Enc2_new >= 127){
161
    Enc2.write(127); 
162
  }
163

  
164
 //Instrument 1 Controls//////////////////////////////////////  
165
 
166
 //Loop/Keymode Switch Instrument 1 
167
   
168
 if (button1.risingEdge()) {   
169
   //Serial.println("Loop mode");
170
   usbMIDI.sendControlChange(cc_play, 1, midi_chan_inst1);
171
 }
172
   
173
 if (button1.fallingEdge()) {   
174
   //Serial.println("Keyboardmode mode");
175
   usbMIDI.sendControlChange(cc_play, 0, midi_chan_inst1);
176
 }
177
     
178
   
179
 //Record Instrument 1
180
 if (button2.fallingEdge()) {   
181
   //Serial.println("RECORD! Instrument 1");
182
   usbMIDI.sendControlChange(cc_record, 1, midi_chan_inst1);
183
 }
184

  
185
 //send MIDI Wavejet 1 [Position Instrument 1]
186
 
187
 if (Jet1_new > Jet1_old+jitter_thresh || Jet1_new < Jet1_old-jitter_thresh) {
188
    
189
    int16_t midiVal = constrain( map(Jet1_new, 24, 926, 0, 149), 0, 149 );
190
    // int16_t midiVal = constrain( map( Jet1_new, 23, 928, 0, 149 ), 0, 149 ); old collidoscope 
191
    if( midiVal != Jet1_old_MIDI ){
192
      Jet1_old_MIDI = midiVal;
193
      usbMIDI.sendPitchBend( midiVal, midi_chan_inst1 );
194
    }
195

  
196
    Jet1_old = Jet1_new;
197
    digitalWrite(Pin_MIDIled, HIGH);
198
 }
199

  
200

  
201
 //send MIDI Filter 1 [Filter Instrument 1]
202

  
203
 if ( filter1_new != filter1_old ) {         // maybe adding jitter threshold needed, see Jet1_new  
204

  
205
    int16_t midiVal = constrain( map(filter1_new, 0, 1024, 0, 127), 0, 127 );
206
    if( midiVal != filter1_old_MIDI){
207
      //Serial.println( midiVal );
208
      filter1_old_MIDI = midiVal;
209
      usbMIDI.sendControlChange(cc_filter, midiVal, midi_chan_inst1);
210
    }
211
    
212
    filter1_old = filter1_new;
213
    digitalWrite(Pin_MIDIled, HIGH);
214
  }
215

  
216
  if ( dur1_new != dur1_old ) {         // maybe adding jitter threshold needed, see Jet1_new  
217
 
218
    int16_t midiVal = constrain( map(dur1_new, 0, 1024, 0, 127), 0, 127 );
219
    if( midiVal != dur1_old_MIDI){
220
      //Serial.println( midiVal );
221
      dur1_old_MIDI = midiVal;
222
      usbMIDI.sendControlChange(cc_duration, midiVal, midi_chan_inst1);
223
    }
224
    
225
    dur1_old = dur1_new;
226
    digitalWrite(Pin_MIDIled, HIGH);
227
  }
228

  
229
  //send MIDI Encoder 1 [Selection length Instrument 1]
230
  if (Enc1_new != Enc1_old) {
231
    Enc1_old = Enc1_new;
232
    //Serial.println("Encoder 1: ");
233
    //Serial.println(Enc1_new);
234
    usbMIDI.sendControlChange(cc_length, Enc1_new, midi_chan_inst1);
235
    digitalWrite(Pin_MIDIled, HIGH);
236
  }
237

  
238
  
239
  
240
  //Instrument 2 Controls//////////////////////////////////////  
241
  
242
  //Loop/Keymode Switch Instrument 2
243
   
244
  if (button3.risingEdge()) {   
245
    //Serial.println("Loop mode");
246
    usbMIDI.sendControlChange(cc_play, 1, midi_chan_inst2);
247
  }
248
  
249
  if (button3.fallingEdge()) {   
250
    //Serial.println("Keyboardmode mode");
251
    usbMIDI.sendControlChange(cc_play, 0, midi_chan_inst2);
252
  }
253
  
254
  //Record Instrument 2
255
  if (button4.fallingEdge()) {   
256
    //Serial.println("RECORD! Instrument 2");
257
    usbMIDI.sendControlChange(cc_record, 1, midi_chan_inst2);
258
  }
259

  
260
  //send MIDI Wavejet 2 [Position Instrument 2]
261
  
262
  if (Jet2_new > Jet2_old+jitter_thresh || Jet2_new < Jet2_old-jitter_thresh) {
263
    //Serial.println("RECORD! Instrument 2");
264
    int16_t midiVal = constrain( map( Jet2_new, 925, 18, 149, 0 ), 0, 149 );
265
    if( midiVal != Jet2_old_MIDI ){
266
      Jet2_old_MIDI = midiVal;
267
      usbMIDI.sendPitchBend( midiVal, midi_chan_inst2 );
268
    }
269

  
270
    Jet2_old = Jet2_new;
271
    digitalWrite(Pin_MIDIled, HIGH);
272
  }
273
  
274
 //Serial.println(filter2_new);
275
   if ( filter2_new != filter2_old ) {         // maybe adding jitter threshold needed, see Jet1_new  
276
    int16_t midiVal = constrain( map(filter2_new, 0, 1024, 0, 127), 0, 127 );
277
    if( midiVal != filter2_old_MIDI){
278
      //Serial.println( midiVal );
279
      filter2_old_MIDI = midiVal;
280
      usbMIDI.sendControlChange(cc_filter, midiVal, midi_chan_inst2);
281
    }
282
    
283
    filter2_old = filter2_new;
284
    digitalWrite(Pin_MIDIled, HIGH);
285
   }
286

  
287
   if ( dur2_new != dur2_old ) {         // maybe adding jitter threshold needed, see Jet1_new  
288
    int16_t midiVal = constrain( map(dur2_new, 0, 1024, 0, 127), 0, 127 );
289
    if( midiVal != dur2_old_MIDI){
290
      //Serial.println( midiVal );
291
      dur2_old_MIDI = midiVal;
292
      usbMIDI.sendControlChange(cc_duration, midiVal, midi_chan_inst2);
293
    }
294
    
295
    dur2_old = dur2_new;
296
    digitalWrite(Pin_MIDIled, HIGH);
297
   }
298
   
299
  
300
  //send MIDI Encoder 2 [Selection length Instrument 2]
301
  if (Enc2_new != Enc2_old) {
302
    Enc2_old = Enc2_new;
303
    //Serial.println("Encoder 2: ");
304
    //Serial.println(Enc2_new);
305
    usbMIDI.sendControlChange(cc_length, Enc2_new, midi_chan_inst2);
306
    digitalWrite(Pin_MIDIled, HIGH);
307
  }
308
    
309
}
310

  

Also available in: Unified diff