Ug I have been beating my head against this all day.
I want to make a MIDI controller with two momentary buttons that sends a series of PC messages, incrementing or decrementing with each press, sending out on 5-pin DIN via the TX pin.
So,
1st press on SW1 = PC0
2nd on SW1 = PC1
3rd on SW1 = PC2
Now I press SW2 and PC1
ect.
I got started here:
https://forum.arduino.cc/index.php?topic=144391.0
I am using the following code, but it doesn't even give me any MIDI output, and I'm dying cuz it is 107 degrees out.
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
const int pinButton = 8;
int buttonstate = 0;
int lastbuttonstate = 0;
int keyispressed = 0;
int currentprogram = 0;
void setup() {
//MIDI.begin(MIDI_CHANNEL_OMNI);
Serial1.begin(31250);
delay(100);
setProgram(currentprogram);
pinMode(pinButton, INPUT_PULLUP);
}
void loop() {
buttonstate = digitalRead(pinButton);
if(buttonstate != lastbuttonstate) {
if (buttonstate == LOW){
//Serial.println("PRESSED");
currentprogram++;
delay (175);
if(currentprogram > 16) currentprogram = 0;
setProgram(currentprogram);
}
else {
}
}
lastbuttonstate = buttonstate;
}
void setProgram(uint8_t p) {
Serial.write((uint8_t)0xC0);
Serial.write((uint8_t)p);}
Has anyone done this, or can anyone lead me in the right direction? If there is an easier way, I'm open to totally new approaches.
I am a bad coder, but reasonable at hacking crap together 
What sort of Arduino are you using?
Serial1.begin(31250);
Implies it is a Leonardo of Micro and you are using Pins 0 & 1 for a MIDI output.
But then the code:-
Serial.write((uint8_t)0xC0);
Implies you have a Uno, in which case you haven't initialised the serial port.
If you have a Uno change that begin command to:-
Serial.begin(31250);
Ah, you are a genius!
I am working on a NANO EVERY, and sending on Serial1. Now I can get real.
in case anyone ever wants to make this, here is my final code.
Well.. I haven't tested to see if there is a PC0 offset... but it works in Midi-Ox, so yay!
Thanks to the masters, as always.
// DigiTech Whammy IV - MIDI Controller.
// by Cameron @the.nw.enterprise, http://thenorthwestenterprise.com/
// Adapted from MichaelJGuitar 2013 and help from GrumpyMike, as always
// Switch allows changing of Whammy preset.
// Configured to increment or decrement with a footswich buttonpress
#include <MIDI.h>
MIDI_CREATE_INSTANCE(HardwareSerial, Serial1, MIDI);
const int upButton = 8;
const int dnButton = 6; //your input pins- wire to footswitches
int upbuttonstate = 0;
int lastupbuttonstate = 0;
int dnbuttonstate = 0;
int lastdnbuttonstate = 0;
int currentprogram = 1;
void setup() {
//MIDI.begin(MIDI_CHANNEL_OMNI);
Serial1.begin(31250);
delay(100);
setProgram(currentprogram);
pinMode(upButton, INPUT_PULLUP);
pinMode(dnButton, INPUT_PULLUP);
}
void loop() {
// define increment button action
upbuttonstate = digitalRead(upButton);
if(upbuttonstate != lastupbuttonstate)
{if (upbuttonstate == LOW)
{currentprogram++;
delay (175);
if(currentprogram > 17) currentprogram = 1;
setProgram(currentprogram);}
else { }
}
// define decrement button action
dnbuttonstate = digitalRead(dnButton);
if(dnbuttonstate != lastdnbuttonstate)
{if (dnbuttonstate == LOW)
{currentprogram--;
delay (175);
if(currentprogram < 1) currentprogram = 17;
setProgram(currentprogram);}
else { }
}
//set variable
lastupbuttonstate = upbuttonstate;
lastdnbuttonstate = dnbuttonstate;
}
void setProgram(uint8_t p) {
Serial1.write((uint8_t)0xC0);
Serial1.write((uint8_t)p);}