I'm kinda new to programming arduino, and i'm trying to build a midi footswitch for amplitube or any other so, i wanted to make the button send a cc message with a value and then when i click again, send the same message but with other value. basically, if click it'll turn what i want on and if i click again it'll turn off.
Here is the code
#define pin 2
void setup() {
Serial.begin(115200);
pinMode(pin, INPUT_PULLUP);
}
void loop() {
static bool oldState = false;
bool state = !digitalRead(pin);
if (oldState != state) {
if (state)CC();
while (!digitalRead(pin));
oldState = state;
delay(100);
}
}
void CC() {
static bool V = true;
Serial.write(0xB0);// CC 1 channel
Serial.write(0x00);// first byte, pick one in range 0-127
Serial.write(V ? 0x7f : 0x00); //value. if each time should be same value than buy me a coffee
Serial.flush();
V = !V;
delay(100);
}