Hi forum.
I just got my first Arduino about two weeks ago so this is my first post.
I am trying to make a sliderpotentiometer control the volume of Cubase via MIDI.
I use the MIDI library and my sketch so far is very inspired by some other posts that i have read.
My problem is that the serial port get totally bombarded with crazy MIDI messages even though it should only be sending when i change the potmeter.
First of all the glitch obbviously is more than the simple bitbug, though i have no smoothing in the code yet. I know this because i monitor the signal with MIDI-OX and S2MIDI. From here i can see that all kinds of messages are being send on all channels at all velocitys.
Secondly is the rate of messages. They come very fast, probably about 20 per second. This again telles me that something is completely wrong.
i know that it is not a hardwarefail since i hvae tested a code that works to do just the same but written in a very other way, without the midi library.
also i have narrowed it down to the "MIDI.sendControlChange" command. The third parameter that controls the midi channel to send to, seems to cause the problem. when i set this to anything else than 1 to 16, it will simply send nothing. whatever i put in the other parameters when it is set to a channel between 1 and 16, the problem is there again.
I really feel like i have been reading half the forum to find out more about this but it just does not make sense to me why the library function will not work like this.
Please look at my code and see what the problem might be.
if it is some lame problem im am very sorry but as mentioned i am very new to Arduino, electronics and programming.
// Written by Jos Mirth for an Arduino Mega 2550. A potentiometer must be conected to analog inputpin A0
// This program cheks for changes in the value of a potentiometer (sliderpot) and sends it, if any, as a MIDI-ControlChange-message to change channelvolume
// It Uses the MIDI library, that can be downloaded from Arduino.cc
// The information runs over the serial usb port. MIDI data is sent as BYTE and at baudrate 31250. For a PC to read this data, two programs are needed on the PC.
// First a program that searches and converts bytes from the serial connection into MIDI date, must be installed. For example use "S2midi"
// Then a virtual MIDI cable must be installed so that the first program has a place to send the data. for example use "LoopBe1"
// Additionally a program called MIDI-OX can be used to monitor and sendback MIDI messages on the PC
#include <MIDI.h> // Includes the MIDI library
int spot1;
int spot1_old;
void setup(){
MIDI.begin(MIDI_CHANNEL_OMNI); // Initiates MIDI-communication on the serial usb port on MIDI-channel 1 by default. Channels go from 1 to 16
// To select specific channel othan than 1, type “MIDI.begin(4);” for channel 4
// To select all channels, type “MIDI.begin(MIDI_CHANNEL_OMNI);”
// Also it enables the Thru, with no filtering (everything caught is sent back)
MIDI.turnThruOff(); // Turns off MIDI thru
}
void loop(){
spot1 = analogRead(A0/8); // Reads spot1 at analog inputpin A1,divided by 8 for midi (0-127)
if (spot1 != spot1_old){ // If value of spot1 has changed
MIDI.sendControlChange(7, spot1, 1);
// Send MIDI ControlChange message with value of spot1
// "7" means "channel volume", "spot1" is the value to write, "1" means write to channel 1
// sendControlChange (byte ControlNumber, byte ControlValue, byte Channel);
// Parameters:
// ControlNumber: The controller number (0 to 127). See http://www.somascape.org/midi/tech/spec.html#ctrlnums
// ControlValue: The value for the specified controller (0 to 127).
// Channel: The channel on which the message will be sent (1 to 16).
spot1_old = spot1; // Updates the stored value of spot1 to enable looping of checking for valuechanges
}
}
DAW_Controller.pde (2.55 KB)