Here's the latest code - it prints the toggle change, the Button/CC#, and either 0 or 127 (if a button is pushed/not pushed).
/* Teensy 4.1 DIY USB-MIDI controller.
*/
#include <Bounce.h>
//The number of push buttons
const int NUM_OF_BUTTONS = 8;
// Create Bounce objects for each button
//button debounce time
const int DEBOUNCE_TIME = 25;
Bounce buttons[NUM_OF_BUTTONS] =
{
Bounce (1, DEBOUNCE_TIME),
Bounce (2, DEBOUNCE_TIME),
Bounce (3, DEBOUNCE_TIME),
Bounce (4, DEBOUNCE_TIME),
Bounce (5, DEBOUNCE_TIME),
Bounce (6, DEBOUNCE_TIME),
Bounce (7, DEBOUNCE_TIME),
Bounce (8, DEBOUNCE_TIME)
};
//Array to the store the CC message value of each button
const int MIDI_CC_NUMS[NUM_OF_BUTTONS] = {24, 25, 26, 27, 20, 21, 22, 23};
bool running = false;
bool toggle_state[NUM_OF_BUTTONS] = {false, false, false, false, false, false, false, false};
//The setup function. Called once when the Teensy is turned on or restarted
void setup()
{
// Configure the pins for input mode with pullup resistors.
// The buttons/switch connect from each pin to ground. Button shorts to ground.
for (int i = 0; i < NUM_OF_BUTTONS; i++)
{
pinMode (i, INPUT_PULLUP);
}
}
//The loop function. Called over-and-over once the setup function has been called.
void loop()
{
// Update all the buttons/switch.
for (int i = 0; i < NUM_OF_BUTTONS+1; i++)
{
buttons[i].update();
}
// Check the status of each push button
{
for (int i = 0; i < NUM_OF_BUTTONS; i++)
{
if (buttons[i].fallingEdge())
{
toggle_state[i] = !toggle_state[i];
}
// Debug code to see button states
{ Serial.println (MIDI_CC_NUMS[i]);
Serial.println ("Toggle State :");
Serial.println (toggle_state[i]);
}
{
if (toggle_state[i])
{ usbMIDI.sendControlChange (MIDI_CC_NUMS[i], 0, 1);
// Debug code to see button CC# passed
Serial.println ("CC # sent change state:");
Serial.println (MIDI_CC_NUMS[i]);
Serial.println (0);
}
else
{ usbMIDI.sendControlChange (MIDI_CC_NUMS[i], 127, 1);
// Debug code to see button CC# passed
Serial.println ("CC # sent change state:");
Serial.println (MIDI_CC_NUMS[i]);
Serial.println (127);
}
}
}
}
// MIDI Controllers should discard incoming MIDI messages.
while (usbMIDI.read())
{
// ignoring incoming messages, so don't do anything here.
}
}
//Modify message
At this point, the buttons are sending the #'s, so i wonder if the MIDI syntax or the CC# is incorrect?
EDITED - ok, so I hooked the Arduino up to my mac and then launched the MIDI setup app. It was recieving MIDI messages, but its not now and hasn't been since I went from "latching infinite on".
I don't quite understand MIDI well enough to know if I shouldn't be using some other send message?