How can I convert my program/preset change code to just serial?

Hello, I have a program that I'm wanting to convert to just serial. Currently it is using the midi.h library. I'm not sure if this can be done? I would appreciate any help. Thanks

#include <SoftwareSerial.h>
SoftwareSerial midi(0,1); ///RX TX

int progNo = 30;
int upLastTime, downLastTime, upNow, downNow;

void setup() { 
midi.begin(31250);
midi.print(1);
pinMode(2, INPUT_PULLUP);
digitalWrite(2, HIGH); // enable pull up
upNow = digitalRead(2);
}


void loop() 
{
//modified code to only do up button
upNow = digitalRead(2);
if (upNow == HIGH && upLastTime == LOW) {
progNo++; // increment program change
progNo&=0x7F; //numbers will never go above 127 and will reset to 0
midi.print(byte(progNo), 1);
delay(20); // bit of debounce delay
} 
upLastTime = upNow;
delay(200);
}

What have you tried and how does it work?

Paul

jovid196168:
I have a program that I'm wanting to convert to just serial. Currently it is using the midi.h library.

I know a little about Serial. I know nothing about midi or music.

You have not provided enough information. What does the midi-based program do? What do you want the serial-based program to do? Will it be something to do with music, or something altogether different?

...R
Serial Input Basics - simple reliable ways to receive data.

I'm guessing that the program you posted is the conversion (since it definitely doesn't use the MIDI library). Does it work? If not what does it do and what should it do?

Why are you using SoftwareSerial but on the hardware Serial pins 0,1? What Arduino is this on? And for interest, what is on the other end of the serial wires that can read the output as though it was a MIDI event?

Steve

I have tested it through a midi monitor and it is sending midi. I haven't tried it yet through a music daw. I think I have to assign it in the daw so it can control, not 100% sure how to do this. But yes it is to do with music, I want to be able to press a button and it cycle upwards through the presets that I have. I saw a few YouTube videos and thought to have a go at this. I'm wanting to add this to my main program that is written in raw midi. I'm building a midi controller/loop pedal. This is the last button I have to add but I wasn't sure if this was possible without midi library. Sorry I didn't give enough information.

jovid196168:
I have tested it through a midi monitor and it is sending midi.

That's interesting...but is it sending Program Change messages? From your code it looks like you are only transmitting a single data byte with a program number in it. The normal first status byte of a Program Change message which defines the type as PC and includes what channel it is for seems to be missing.

So it is relying on MIDI "running status" to define the message type/channel, which is dangerous. Unless you are planning on only ever sending a stream of PC messages without ever sending any other type of MIDI message it's not going to work.

Steve