Hello,
Currently using an HP4067 on a breakout board with 16 pots connected to a 4.1, sending MIDI over serial UART to another device, which allows me to see the MIDI readings on the computer.
Using a modified version of the code I found, the reading from my pots look fine in the serial monitor, but when looking at the readings on the computer (in MIDI form), they're all over the place. The values skip around, turning one knob won't work, but a whole other value will begin to turn, some don't work at all. However, if I apply a delay of at least 3 milliseconds, all of the values read perfectly fine. If there's a delay of one or two milliseconds, the skipping returns.
All of the pins are in order on the board and in the code. Digital pins S0 - S3 are on pins 2 - 5. The analog pin is connected to pin 38. If this is significant, the TX I'm using is right next door at pin 2, and pin 1 RX is not in use. There is no accidental contact between any of the pins.
Before getting the multiplexer, the pots were connected to the board itself. There were no issues with how they behaved. Using the same computer program, they never skipped around like they are after hooking them up to the multiplexer. Should I debounce the digital pins? It's not a long enough delay for it to make a very discernible difference, but I'm not sure if the delay there will cause me a headache further down in the code. Thanks!
Unrelated bonus question: Is it necessary to mount the Teensy Audio Board directly on the pins of the Teensy, or is it possible instead to use similar available pins and mount it elsewhere?
Currently using an HP4067 on a breakout board with 16 pots connected to a 4.1, sending MIDI over serial UART to another device, which allows me to see the MIDI readings on the computer.
Using a modified version of the code I found, the reading from my pots look fine in the serial monitor, but when looking at the readings on the computer (in MIDI form), they're all over the place. The values skip around, turning one knob won't work, but a whole other value will begin to turn, some don't work at all. However, if I apply a delay of at least 3 milliseconds, all of the values read perfectly fine. If there's a delay of one or two milliseconds, the skipping returns.
All of the pins are in order on the board and in the code. Digital pins S0 - S3 are on pins 2 - 5. The analog pin is connected to pin 38. If this is significant, the TX I'm using is right next door at pin 2, and pin 1 RX is not in use. There is no accidental contact between any of the pins.
Before getting the multiplexer, the pots were connected to the board itself. There were no issues with how they behaved. Using the same computer program, they never skipped around like they are after hooking them up to the multiplexer. Should I debounce the digital pins? It's not a long enough delay for it to make a very discernible difference, but I'm not sure if the delay there will cause me a headache further down in the code. Thanks!
Code:
#include <MIDI.h>
#define muxIn 38
#define muxPin0 2
#define muxPin1 3
#define muxPin2 4
#define muxPin3 5
int CCChan[] = {22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37};
int potVal[16];
int initPot[16];
int lastInitPot[16];
MIDI_CREATE_DEFAULT_INSTANCE();
void setup()
{
pinMode(muxPin0, OUTPUT);
pinMode(muxPin1, OUTPUT);
pinMode(muxPin2, OUTPUT);
pinMode(muxPin3, OUTPUT);
MIDI.begin();
//Serial.begin(9600); //optional for viewing print lines below
}
void loop()
{
for(int i = 0; i < 16; i++) {
byte channel = (i);
digitalWrite(muxPin0, bitRead(channel, 0));
digitalWrite(muxPin1, bitRead(channel, 1));
digitalWrite(muxPin2, bitRead(channel, 2));
digitalWrite(muxPin3, bitRead(channel, 3));
initPot[i] = (map(analogRead(muxIn), 0, 1023, 0, 127));
if(initPot[i] != lastInitPot[i]){
lastInitPot[i] = initPot[i];
potVal[i] = initPot[i];
delay(3);
MIDI.sendControlChange(CCChan[i], potVal[i], 1);
}
/* Serial.print("Channel: "); // left this in, in case it comes in handy.
Serial.println(CCChan[i]);
Serial.println(" ");
Serial.print("Pot Value: ");
Serial.println(potVal[i]);
Serial.println(" ");
delay(300);//*/
}
}
Unrelated bonus question: Is it necessary to mount the Teensy Audio Board directly on the pins of the Teensy, or is it possible instead to use similar available pins and mount it elsewhere?