@tim:
You should be able to use the PITCHBEND & MODWHEEL pots exactly as wired. PITCHBEND usually has some mechanical mechanism to return it to center when not activated, so I'll assume that this is the case in my functional description below.
Just to make sure that the PITCHBEND & MODWHEEL pots are operating as expected, execute the following:
1)
make sure that no more than 3.3VDC is connected to the (V+) terminal in your schematic above (the T4.1 is *NOT* 5V tolerant)
2) connect the output from the MODWHEEL pot to pin 15 (analog input A1)
3) with the MODWHEEL turned all the way counter-clockwise, measure the voltage (you should get very nearly either 3.3VDC or 0VDC)
4) with the MODWHEEL turned all the way clockwise, measure the voltage (you should get very nearly either 0VDC or 3.3VDC)
5) disconnect the output from the MODWHEEL pot from pin 15 (analog input A1) & connect the output from the PITCHBEND pot to pin 15 (analog input A1)
6) with the PITCHBEND in the centered (inactivated) position, measure the voltage (you should get very nearly 1.65VDC)
7) with the PITCHBEND turned all the way counter-clockwise, measure the voltage (you should get very nearly either 3.3VDC or 0VDC)
8) with the PITCHBEND turned all the way clockwise, measure the voltage (you should get very nearly either 0VDC or 3.3VDC)
If/when you are satisfied that the PITCHBEND & MODWHEEL pots are operating as expected, then proceed with the following:
Program your T4.1 with the following:
Code:
void setup() {
Serial.begin(9600);
pinMode(15, INPUT_DISABLE);
}
void loop() {
int adc_in = analogRead(15);
Serial.print("A1 (pin 15) analog input = ");
Serial.println(adc_in);
delay(1000);
}
To determine the characteristics of the PITCHBEND & MODWHEEL pots that you will be monitoring, execute the following:
1) load & execute the sketch given above, while monitoring the output in the Arduino IDE Serial Monitor
2) connect the output from the MODWHEEL pot to pin 15 (analog input A1)
3) rotate the MODWHEEL from fully counter-clockwise to fully clockwise & note the values reported, while also noting in which direction (CW or CCW) that the minimum & maximum counts are reported - note the count at fully counter-clockwise as countModCCW (very nearly 0 or 1023), and note the count at fully clockwise as countModCW (very nearly 1023 or 0)
4) disconnect the output from the MODWHEEL pot from pin 15 (analog input A1) & connect the output from the PITCHBEND pot to pin 15 (analog input A1)
5) connect the output from the PITCHBEND pot to pin 15 (analog input A1)
6) mote the count at the PITCHBEND centered position as countPitchCenter (should be very nearly 512)
7) rotate the PITCHBEND from fully counter-clockwise to fully clockwise & note the values reported, while also noting in which direction (CW or CCW) that the minimum & maximum counts are reported - note the count at fully counter-clockwise as countpitchCCW (very nearly 0 or 1023), and note the count at fully clockwise as countpitchCW (very nearly 1023 or 0)
Now, for the real magic !! You will use the values determined above to be able to make use of the PITCHBEND & MODWHEEL pots in your sketch.
If your countModCCW is close to zero & your countModCW is close to 1023, then you have a MODWHEEL pot that increases in the clockwise direction. Let's say you want an actual MODWHEEL range from 0-100. If so, you would use the following command to make that translation directly & linearly:
Code:
MODpercent = map(adc_in, 0,1023, 0, 100);
If, however, your countModCCW is close to 1023 & your countModCW is close to 0, then you have a MODWHEEL pot that increases in the counter-clockwise direction. You still want an actual MODWHEEL range from 0-100. If so, you would use the following command to make that translation directly & linearly:
Code:
MODpercent = map(adc_in, 1023, 0, 0, 100);
PITCHBEND is a little more complicated. In my TeensyMIDIPolySynth, my PITCHBEND wheel sends a MIDI value between -8192 and +8192, so I'll use that range as an example. You'll need to decide what range you want your PITCHBEND pot to actually generate. I also like a small "deadband" in the middle of my PITCHBEND range so that a slight wobble of the PITCHBEND wheel doesn't cause any change. I'll use a "deadband" value of "5" (which gives an actual range of 10 counts on either side of the middle).
Your PITCHBEND pot should hover around a returned value of 512 when centered.
If your countPitchCCW is close to zero & your countPitchCW is close to 1023, then you have a PITCHBEND pot that increases in the clockwise direction. You want the calculated value of pitchbend to range from -8192 to +8192, with a center value of 0 (in this example). So, you would use the following to make the translation directly & linearly from input values to range values, with the desired "deadband" in the middle:
Code:
int countPitchCenter = 512; // use your actual measured value
int countPitchCW = 1023; // use your actual measured value
int countPitchCCW = 0; // use your actual measured value
int pitchValue;
int deadband = 5;
int adc_in = analogRead(15);
if (adc_in < (countPitchCenter - deadband)) {
pitchValue = map(adc_in, countPitchCCW, countPitchCenter, -8192, -1);
} else {
if (adc_in > (countPitchCenter + deadband)) {
pitchValue = map(adc_in, countPitchCenter, countPitchCW, 1, 8192);
} else {
pitchValue = 0;
}
}
If, however, your countPitchCCW is close to 1023 & your countPitchCW is close to 0, then you have a PITCHBEND pot that increases in the counter-clockwise direction. You still want the calculated value of pitchbend to range from -8192 to +8192, with a center value of 0 (in this example). So, you would use the following to make that translation directly & linearly, with the desired "deadband" in the middle:
Code:
int countPitchCenter = 512; // use your actual measured value
int countPitchCW = 0; // use your actual measured value
int countPitchCCW = 1023; // use your actual measured value
int pitchValue;
int deadband = 5;
int adc_in = analogRead(15);
if (adc_in > (countPitchCenter + deadband)) {
pitchValue = map(adc_in, countPitchCW, countPitchCenter, -8192, -1);
} else {
if (adc_in < (countPitchCenter - deadband)) {
pitchValue = map(adc_in, countPitchCenter, countPitchCCW, 1, 8192);
} else {
pitchValue = 0;
}
}
In the end, you'll need to wire the outputs from the two individual pots (PITCHBEND & MODWHEEL) to separate analog inputs & adjust your final sketch appropriately to read each individually, but I just wanted to give you some simple examples of how you might handle the specific voltages provided by the pots as they are actually wired. Hope this helps !!
This was all generated on-the-fly & has not been tested on actual hardware, so hopefully, no stupid mistakes have crept their way into this attempted description. Nothing worse than a non-working example to get someone frustrated !!
Mark J Culross
KD5RXT
NOTE: edited multiple times to correct mistakes & omissions !!
NOTE: edited again to correct INPUT_NONE to INPUT_DISABLE
NOTE: edited yet again to add missing parentheses & semicolons (geesh !!)