#include <frequencyToNote.h>
#include <MIDIUSB.h>
#include <pitchToFrequency.h>
#include <pitchToNote.h>
#define INPUT_PIN_7 7
#define SELECT_PIN_8 8
#define SELECT_PIN_9 9
#define SELECT_PIN_10 10
#define SELECT_PIN_11 11
unsigned long debounce;
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode(SELECT_PIN_8, OUTPUT); //setting multiplexer selector pins to output
pinMode(SELECT_PIN_9, OUTPUT);
pinMode(SELECT_PIN_10, OUTPUT);
pinMode(SELECT_PIN_11, OUTPUT);
pinMode(INPUT_PIN_7, INPUT); //setting multiplexer input to pin 7 input
}
void loop() {
digitalWrite(SELECT_PIN_8, LOW); //selecting Y0 input on the multiplexer
digitalWrite(SELECT_PIN_9, LOW); //selecting Y0 input on the multiplexer
digitalWrite(SELECT_PIN_10, LOW); //selecting Y0 input on the multiplexer
digitalWrite(SELECT_PIN_11, LOW); //selecting Y0 input on the multiplexer
if (digitalRead(INPUT_PIN_7) == HIGH && millis() - debounce > 100){
controlChange(0,1,1);
debounce = millis();
}
}
controlChange is from the MIDIUSB library. I am using some software to monitor midi inputs and when I click the button once it writes like 200 lines of inputs or something, then stops. "debounce" is an unsigned long variable.
The way I expect this to work is that when the button is pressed (HIGH) and the current millis-debounce is greater than 100ms it will send the control change, then update debounce to be the current time so as to stop multi triggering. But all it seems to do is spam the output a bunch then stop.