Hi guys,
I'm building a MIDI controller and I need to be able to use my potentiometers to control different parameters when a button is pressed (i.e switching banks). I've set up a counter, the value of which determines what MIDI CC command is sent, but this only works while the button is pressed. I can switch between CC 74 and CC 75 but only while I hold down the modePin button (8). I've checked out various tutorials and projects but the different types of values I need to check and write and read to have got me lost. So here's what I have so far:
#include <Bounce.h>
const int channel = 1;
int buttonState; // The previous state of the button recorded here
int notePin = (7);
int modePin = (8);
int val; // the current value of the button
int mode; // the mode I want to send out the CC data on (74 or 75, basically)
Bounce button1 = Bounce(7, 5);
Bounce button2 = Bounce(8, 5);
void setup() {
pinMode(7, INPUT_PULLUP);
pinMode(8, INPUT_PULLUP);
buttonState = digitalRead(modePin);
}
void loop() {
val = digitalRead(modePin); //what state is the button in?
if (val != buttonState) // is this what it was before?
{
if (val == HIGH) // if it's ON, then increment the mode value. Otherwise, decrement it.
{
mode++;
}else{
mode--;
}
}
buttonState = val; // remember the state of the button
{ //if mode is 0, the analog value (/8) is sent out as a CC 74, otherwise as a 75
if (mode == 0){
usbMIDI.sendControlChange(74, analogRead(0) / 8, channel);
}
else
{
usbMIDI.sendControlChange(75, analogRead(0) / 8, channel);
}
}
button1.update(); // code to make my other button send out a note on C4.
if (button1.fallingEdge()) {
usbMIDI.sendNoteOn(60, 99, 1); // 60 = C4
}
if (button1.risingEdge()) {
usbMIDI.sendNoteOff(60, 0, 1); // 60 = C4
}
}
This does sent out MIDI data as CC 75 and I can change it to CC 74 but I can't get it to stay as 74 or 75 until the button is pressed again.
Any help would be greatly appreciated!
Thanks,
Ben