Good day forum users.
I am a music student from South Africa, hoping to get some pointers.
My ultimate goal is to build a class compliant MIDI Ondes Martenot with Arduino, I am currently using Arduino UNO but will eventually upgrade to something with higher resolution ADC for pitch bend. For the time being however, I will be taking baby steps because there are quite a few concepts involved that I am yet to fully comprehend.
For those who are unfamiliar with the Ondes Martenot, here are a few links:
I am not the first to want to make a MIDI version of the instrument, infact one Mitshubi Abe made such a device in 2012 and I will be basing the my hardware and my code on his version as it seems to work quite all right.
Watch his video demonstration here:
And his code is available on his blog here:
http://gam.boo.jp/blog/archives/2012/09/midiondes_marte.html
Now, I tried my very best to decipher his code but I get errors all over the show. So I have decided to break it into little pieces, the first of which is note on/off on MIDI channel 1, controlled by a switch, and Channel volume controlled by a sensor (potentiometer for prototyping). Just to clarify, when the button is pressed the message note on, middle C, velocity 127 is sent. The volume of that note is then controlled by the sensor which is linked to channel volume.
This is my current predicament. I have my arduino speaking to FL studio via hairless MIDI and I am getting a middle C at velocity 127 every minute or so. The switch does nothing, the pot does nothing.
Here is the sketch, clearly I have made some horrid mistakes. I urge you to point them out and help me correct them
#include <MIDI.h>
#define SWITCH 7
int volumeSensor = 0;
int volumeValue;
int MidiValue = 0;
int Old_midiValue;
int cc = 7; // channel volume
int Notecounter = 0;
int val1 = 0;
int MIDI_ROOT_NOTE = 60;
MIDI_CREATE_DEFAULT_INSTANCE();
void SendMIDI (char cmd, char data1, char DATA2){
Serial.write (byte(cmd));
Serial.write (byte(data1));
Serial.write (byte(DATA2));
}
void Control(){
val1 = digitalRead(SWITCH);
if (val1 = HIGH){
Notecounter = Notecounter +1;
if (Notecounter == 1)
{
SendMIDI(0x90, MIDI_ROOT_NOTE, 127);
}
}
else{
SendMIDI(0x80, MIDI_ROOT_NOTE, 127);
Notecounter = 0;
}
}
void Volume(){
volumeValue = analogRead(volumeSensor);
MidiValue = volumeValue / 7.6;
if (MidiValue > 127){
MidiValue = 127;
}
if (MidiValue = Old_midiValue){
SendMIDI (0xB0, cc, MidiValue);
}
Old_midiValue = MidiValue;
}
void setup() {
MIDI.begin (MIDI_CHANNEL_OFF);
Serial.begin(115200);
}
void loop() {
Control();
Volume();
delay (1);
}