-
Notifications
You must be signed in to change notification settings - Fork 18
/
HWControls.h
138 lines (122 loc) · 4.16 KB
/
HWControls.h
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
// This optional setting causes Encoder to use more optimized code,
// It must be defined before Encoder.h is included.
#define ENCODER_OPTIMIZE_INTERRUPTS
#include <Encoder.h>
#include <Bounce.h>
#include <ADC.h>
#include <ADC_util.h>
ADC *adc = new ADC();
//Teensy 3.6 - Mux Pins
#define MUX_0 28
#define MUX_1 27
#define MUX_2 26
#define MUX_3 25
#define MUX1_S 38
#define MUX2_S A22
//Mux 1 Connections
#define MUX1_noiseLevel 0
#define MUX1_pitchLfoRate 1
#define MUX1_pitchLfoWaveform 2
#define MUX1_pitchLfoAmount 3
#define MUX1_detune 4
#define MUX1_oscMix 5
#define MUX1_filterAttack 6
#define MUX1_filterDecay 7
#define MUX1_pwmAmountA 8
#define MUX1_waveformA 9
#define MUX1_pitchA 10
#define MUX1_pwmAmountB 11
#define MUX1_waveformB 12
#define MUX1_pitchB 13
#define MUX1_pwmRate 14
#define MUX1_pitchEnv 15
//Mux 2 Connections
#define MUX2_release 0
#define MUX2_sustain 1
#define MUX2_decay 2
#define MUX2_attack 3
#define MUX2_filterLFOAmount 4
#define MUX2_FXMix 5
#define MUX2_FXAmount 6
#define MUX2_glide 7
#define MUX2_filterEnv 8
#define MUX2_filterRelease 9
#define MUX2_filterSustain 10
#define MUX2_filterType 11
#define MUX2_resonance 12
#define MUX2_cutoff 13
#define MUX2_filterLFORate 14
#define MUX2_filterLFOWaveform 15
//Teensy 3.6 Pins
#define OSC_FX_SW 39
#define FILTER_LFO_RETRIG_SW 30
#define UNISON_SW 36
#define TEMPO_SW 16
#define RECALL_SW 17
#define SAVE_SW 24
#define SETTINGS_SW 12
#define BACK_SW 10
#define VOLUME_POT A14
#define ENCODER_PINA 4
#define ENCODER_PINB 5
#define RETRIG_LED 34
#define TEMPO_LED 35
#define UNISON_LED 37
#define OSC_FX_LED 14
#define MUXCHANNELS 16
#define QUANTISE_FACTOR 15//Window of noise before change detected in controls. 15 is 4 bits
#define DEBOUNCE 30
static byte muxInput = 0;
static int mux1ValuesPrev[MUXCHANNELS] = {};
static int mux2ValuesPrev[MUXCHANNELS] = {};
static int mux1Read = 0;
static int mux2Read = 0;
static int volumeRead = 0;
static int volumePrevious = 0;
static long encPrevious = 0;
//These are pushbuttons and require debouncing
Bounce oscFXSwitch = Bounce(OSC_FX_SW, DEBOUNCE);
Bounce filterLFORetrigSwitch = Bounce(FILTER_LFO_RETRIG_SW, DEBOUNCE);
Bounce unisonSwitch = Bounce(UNISON_SW, DEBOUNCE);
Bounce tempoSwitch = Bounce(TEMPO_SW, DEBOUNCE);
Bounce recallButton = Bounce(RECALL_SW, DEBOUNCE); //On encoder
boolean recall = true; //Hack for recall button
Bounce saveButton = Bounce(SAVE_SW, DEBOUNCE);
boolean del = true; //Hack for save button
Bounce settingsButton = Bounce(SETTINGS_SW, DEBOUNCE);
boolean reini = true; //Hack for settings button
Bounce backButton = Bounce(BACK_SW, DEBOUNCE);
boolean panic = true; //Hack for back button
Encoder encoder(ENCODER_PINB, ENCODER_PINA);//This often needs the pins swapping depending on the encoder
void setupHardware()
{
//Volume Pot is on ADC0
adc->adc0->setAveraging(16); // set number of averages 0, 4, 8, 16 or 32.
adc->adc0->setResolution(12); // set bits of resolution 8, 10, 12 or 16 bits.
adc->adc0->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_LOW_SPEED); // change the conversion speed
adc->adc0->setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED); // change the sampling speed
//MUXs on ADC1
adc->adc1->setAveraging(16); // set number of averages 0, 4, 8, 16 or 32.
adc->adc1->setResolution(12); // set bits of resolution 8, 10, 12 or 16 bits.
adc->adc1->setConversionSpeed(ADC_CONVERSION_SPEED::VERY_LOW_SPEED); // change the conversion speed
adc->adc1->setSamplingSpeed(ADC_SAMPLING_SPEED::MED_SPEED); // change the sampling speed
//Mux address pins
pinMode(MUX_0, OUTPUT);
pinMode(MUX_1, OUTPUT);
pinMode(MUX_2, OUTPUT);
pinMode(MUX_3, OUTPUT);
//Switches
pinMode(OSC_FX_SW, INPUT_PULLUP);
pinMode(FILTER_LFO_RETRIG_SW, INPUT_PULLUP);
pinMode(UNISON_SW, INPUT_PULLUP);
pinMode(TEMPO_SW, INPUT_PULLUP);
pinMode(RECALL_SW, INPUT_PULLUP); //On encoder
pinMode(SAVE_SW, INPUT_PULLUP);
pinMode(SETTINGS_SW, INPUT_PULLUP);
pinMode(BACK_SW, INPUT_PULLUP);
//LEDs
pinMode(RETRIG_LED, OUTPUT);
pinMode(TEMPO_LED, OUTPUT);
pinMode(UNISON_LED, OUTPUT);
pinMode(OSC_FX_LED, OUTPUT);
}