Hello,
The device that my Teensy 4.1 will be transmitting MIDI to has trouble taking anything except serial midi via UART. Not entirely sure how it works, but serial-only is the solution. I definitely need help with this one.
So what I have below is a modified version of the Mini Untztrument code, with the Trellis Test startup flash stuffed into it. It's a horrible beast of code and it's pretty telling of where I'm at. I'm aware that there are ways of condensing the code with the pots, but the logic is still a little over my head. Either way, it shows up in Midi Monitor when used with usbMIDI so all of the physical components definitely work.
In a previous incarnation of this sketch, I tried to add the MIDI library and create a default instance and build a bunch of duplicates of the analog reads around it. It was really ugly, worked for a second, and froze the controller. If I recall correctly, the MIDI and usbMIDI libraries are separate from each other and can work independently if used in the same sketch. That's a shot in the dark though, all of the extra midi code has been removed.
The device I'm plugging into , the Axoloti, has only responded to the midi output test found on the Teensy MIDI library page. I tried to program a single pot into that sketch and got no response, but likely because I programmed it wrong.
Thank you, and without further ado, the code:
#include <Wire.h>
#include <Adafruit_Trellis.h>
#define LED 13 // Pin for heartbeat LED (shows code is working)
#define CHANNEL 1
Adafruit_Trellis trellis;
uint8_t heart = 0;
unsigned long prevReadTime = 0L;
uint8_t pot1;
uint8_t pot2;
uint8_t pot3;
uint8_t pot4;
uint8_t pot5;
uint8_t pot6;
uint8_t pot7;
uint8_t pot8;
uint8_t pot9;
uint8_t pot10;
uint8_t pot11;
uint8_t pot12;
uint8_t note[] = {
60, 61, 62, 63,
56, 57, 58, 59,
52, 53, 54, 55,
48, 49, 50, 51
};
void setup() {
pinMode(LED, OUTPUT);
for (uint8_t i=0; i<60; i++) {
trellis.setLED(i);
trellis.writeDisplay();
delay(50);
}
for (uint8_t i=0; i<60; i++) {
trellis.clrLED(i);
trellis.writeDisplay();
delay(50);
} // Pass I2C address
#ifdef __AVR__ // this part is optional in the code. not sure if there's any consequence to leaving it
//TWBR = 12;
# endif
// trellis.clear();
// trellis.writeDisplay();
pot1 = map(analogRead(24), 0, 1023, 0, 127);
pot2 = map(analogRead(25), 0, 1023, 0, 127);
pot3 = map(analogRead(26), 0, 1023, 0, 127);
pot4 = map(analogRead(27), 0, 1023, 0, 127);
pot5 = map(analogRead(38), 0, 1023, 0, 127);
pot6 = map(analogRead(39), 0, 1023, 0, 127);
pot7 = map(analogRead(40), 0, 1023, 0, 127);
pot8 = map(analogRead(41), 0, 1023, 0, 127);
pot9 = map(analogRead(14), 0, 1023, 0, 127);
pot10 = map(analogRead(15), 0, 1023, 0, 127);
pot11 = map(analogRead(16), 0, 1023, 0, 127);
pot12 = map(analogRead(17), 0, 1023, 0, 127);
usbMIDI.sendControlChange(22, pot1, CHANNEL);
usbMIDI.sendControlChange(23, pot2, CHANNEL);
usbMIDI.sendControlChange(24, pot3, CHANNEL);
usbMIDI.sendControlChange(25, pot4, CHANNEL);
usbMIDI.sendControlChange(26, pot5, CHANNEL);
usbMIDI.sendControlChange(27, pot6, CHANNEL);
usbMIDI.sendControlChange(28, pot7, CHANNEL);
usbMIDI.sendControlChange(29, pot8, CHANNEL);
usbMIDI.sendControlChange(30, pot9, CHANNEL);
usbMIDI.sendControlChange(31, pot10, CHANNEL);
usbMIDI.sendControlChange(32, pot11, CHANNEL);
usbMIDI.sendControlChange(33, pot12, CHANNEL);
}
void loop() {
unsigned long t = millis();
if((t - prevReadTime) >= 20L) { // 20ms = min Trellis poll time
if(trellis.readSwitches()) {
for(uint8_t i=0; i<16; i++) {
if(trellis.justPressed(i)) {
usbMIDI.sendNoteOn(note[i], 127, CHANNEL);
trellis.setLED(i);
} else if(trellis.justReleased(i)) {
usbMIDI.sendNoteOff(note[i], 0, CHANNEL);
trellis.clrLED(i);
}
}
trellis.writeDisplay();
}
uint8_t newpot1 = map(analogRead(24), 0, 1023, 0, 127);
if(pot1 != newpot1) {
pot1 = newpot1;
usbMIDI.sendControlChange(22, pot1, CHANNEL);
}
uint8_t newpot2 = map(analogRead(25), 0, 1023, 0, 127);
if(pot2 != newpot2) {
pot2 = newpot2;
usbMIDI.sendControlChange(23, pot2, CHANNEL);
}
uint8_t newpot3 = map(analogRead(26), 0, 1023, 0, 127);
if(pot3 != newpot3) {
pot3 = newpot3;
usbMIDI.sendControlChange(24, pot3, CHANNEL);
}
uint8_t newpot4 = map(analogRead(27), 0, 1023, 0, 127);
if(pot4 !=newpot4) {
pot4 = newpot4;
usbMIDI.sendControlChange(25, pot4, CHANNEL);
}
uint8_t newpot5 = map(analogRead(38), 0, 1023, 0, 127);
if(pot5 != newpot5) {
pot5 = newpot5;
usbMIDI.sendControlChange(26, pot5, CHANNEL);
}
uint8_t newpot6 = map(analogRead(39), 0, 1023, 0, 127);
if(pot6 != newpot6) {
pot6 = newpot6;
usbMIDI.sendControlChange(27, pot6, CHANNEL);
}
uint8_t newpot7 = map(analogRead(40), 0, 1023, 0, 127);
if(pot7 != newpot7) {
pot7 = newpot7;
usbMIDI.sendControlChange(28, pot7, CHANNEL);
}
uint8_t newpot8 = map(analogRead(41), 0, 1023, 0, 127);
if(pot8 !=newpot8) {
pot8 = newpot8;
usbMIDI.sendControlChange(29, pot8, CHANNEL);
}
uint8_t newpot9 = map(analogRead(14), 0, 1023, 0, 127);
if(pot9 != newpot9) {
pot9 = newpot9;
usbMIDI.sendControlChange(30, pot9, CHANNEL);
}
uint8_t newpot10 = map(analogRead(15), 0, 1023, 0, 127);
if(pot10 != newpot10) {
pot10 = newpot10;
usbMIDI.sendControlChange(31, pot10, CHANNEL);
}
uint8_t newpot11 = map(analogRead(16), 0, 1023, 0, 127);
if(pot11 != newpot11) {
pot11 = newpot11;
usbMIDI.sendControlChange(32, pot11, CHANNEL);
}
uint8_t newpot12 = map(analogRead(17), 0, 1023, 0, 127);
if(pot12 !=newpot12) {
pot12 = newpot12;
usbMIDI.sendControlChange(33, pot12, CHANNEL);
}
prevReadTime = t;
digitalWrite(LED, ++heart & 32); // Blink = alive
}
while(usbMIDI.read());