Making a simple MIDI Controller. One Man's Journey

Hi Matt,
Sorry if I confused you, always possible at a distance.

First of all if you are using a Uno and want to use the normal serial port for debugging then they suggest using Pin4 on the Uno as a Softserial ouput. This effectively uses a normal output port and bit-bangs it to make it appear as a serial port. Pretty handy coding coding. So the Fluxamasynth jumper would be on [center + Pin4]. If you want to send Midi with less software overhead then you should use a dedicated serial port, and the Fluxamasynth jumper [center+ Pin1] would connect it to the Serial out and share it with the Serial to the USB/screen terminal. This does work as I have used it but it has one major draw back that the Serial to the terminal can be interpreted by the Fluxamasynth as notes and produce some rather startling results, or sometimes nothing at all.

Below is my example of a simple "drum machine" EDIT: Sorry I have sent this before, my apologies :frowning: however comparing it to the ADC one you are trying may give you some more ideas.

// These constants won't change.


#include "Fluxamasynth.h"

# define bass 36              // Define midi note numbers for several GM drum sounds
# define snare 38
# define hihatC 42
# define hihatP 44
# define hihatO 46

Fluxamasynth synth;		// create a synth object

// * Some basic settings */
int channel = 9;              // MIDI channel number
int tempo = 127;              // Start tempo

const int pad0 = A0;  // Analog input pin that the potentiometer is attached to
const int pad1 = A1;  // Analog input pin that the potentiometer is attached to
const int pad2 = A2;  // Analog input pin that the potentiometer is attached to
const int ledPin = 13;       // LED connected to digital pin 13

int sensor0 = 0;         // value read from the sensor
int perc_0 = 45;         //Center
int sensor1 = 0;         // value read from the sensor
int perc_1 = 49;         //LHS
int sensor2 = 0;         // value read from the sensor
int perc_2 = 38;          //RHS
int trapADC = 0;            //used to trap the reading
int trapSensor = 0;
int sensorHi = 0;
int sensorLo = 2000;
int trigger = 0;
int hiHys = 500;
int loHys = 100;
int vel = 120;

void setup() {
  //Use the LED as a monitor
  pinMode(ledPin, OUTPUT);              // sets the digital pin as output
  // initialize serial communications to Midi 31,250 bps
  // Serial.begin(31250);		        //  Set MIDI baud rate:
  //Set up the Midi
  
  synth.midiReset();                    // Do a complete MIDI reset
  synth.setChannelVolume(channel, 127); // max. channel volume
  synth.setMasterVolume(255);	        // max. master volume
  //synth.noteOn(channel, hihatP, vel);	// play a note
  
  Serial.begin(9600);		        // just for debug only

}

void loop() {
  // read the analogs into values:
  sensor0 = analogRead(pad0);
  sensor1 = analogRead(pad1);
  sensor2 = analogRead(pad2);
  // determine alarm status
  if (sensor0 > hiHys)
  {
    digitalWrite(ledPin, HIGH);   // sets the LED on
  }
  else
  {
    digitalWrite(ledPin, LOW);    // sets the LED off
  }

  if (sensor0 > hiHys){
    synth.noteOn(channel, perc_0, vel);	// play a note
    synth.noteOff(channel, perc_0);    
    trapADC = A0;
    trapSensor = sensor0;
  }
  if (sensor1 > hiHys){
    synth.noteOn(channel, perc_1, vel);	// play a note
    synth.noteOff(channel, perc_1);    
    trapADC = A1;
    trapSensor = sensor1;
  }
  if (sensor2 > hiHys){
    synth.noteOn(channel, perc_2, vel);	// play a note
    synth.noteOff(channel, perc_2);    
    trapADC = A2;
    trapSensor = sensor2;
  }
  while (trapSensor > hiHys ){
    delay(10);
    trapSensor = analogRead(trapADC);

  }
  while (trapSensor < loHys){
    delay(10);
    trapSensor = analogRead(trapADC);

  }
  // wait 10 milliseconds before the next loop
  // for the analog-to-digital converter to settle
  // after the last reading:
}

void update(){
  //delay(1000);
  Serial.print("Sensor A0 = " );
  Serial.print(sensor0,DEC);
  Serial.print(" Sensor A1 = " );
  Serial.print(sensor1,DEC);
  Serial.print(" Sensor A2 = " );
  Serial.print(sensor2,DEC);
  Serial.print(" Sensor lo = " );
  Serial.print(hiHys,DEC);
  Serial.print(" Sensor hi = " );
  Serial.println(loHys,DEC);
  Serial.println();
}
/*
Bass  	KeyNum	Sound
A_	33	Metronome Click
B_b	34	Metronome Bell
B_	35	Acoustic Bass Drum
C	36	Bass Drum 1
C#	37	Side Stick
D	38	Acoustic Snare
Eb	39	Hand Clap
E	40	Electric Snare
F	41	Low Floor Tom
F#	42	Closed Hi-Hat
G	43	High Floor Tom
G#	44	Pedal Hi-Hat
A	45	Low Tom
Bb	46	Open Hi-Hat
Bn	47	Low-Mid Tom
c	48	Hi-Mid Tom
c#	49	Crash Cymbal 1
d	50	High Tom
eb	51	Ride Cymbal 1
e	52	Chinese Cymbal
f	53	Ride Bell
f#	54	Tambourine
g	55	Splash Cymbal
g#	56	Cowbell
a	57	Crash Cymbal 2
bb	58	Vibraslap
bn	59	Ride Cymbal 2
C	60	Hi Bongo
C#	61	Low Bongo
D	62	Mute Hi Conga
D#	63	Open Hi Conga
E	64	Low Conga
F	65	High Timbale
F#	66	Low Timbale
G	67	High Agogo
G#	68	Low Agogo
A	69	Cabasa
Bb	70	Maracas
Bn	71	Short Whistle
c	72	Long Whistle
c#	73	Short Guiro
d	74	Long Guiro
d#	75	Claves
e	76	Hi Wood Block
f	77	Low Wood Block
f#	78	Mute Cuica
g	79	Open Cuica
g#	80	Mute Triangle
a	81	Open Triangle
	82	
	83	
	84	
*/

However if you are using a Mega2560 the whole thing gets simpler as you can use the Serial Out 2 and just connect a flying lead to the middle jumper pin on the Fluxamasyth. The header clip is therefore not required. No special bit banging libraries are required and the serial port runs at top speed with no extra CPU overheads. Here are some setup code:

  Serial.begin(115200); //Serial interface for Debugging
  Serial.println("MIDI Begins..");
  Serial2.begin(31250); //set up Serial Interface 2 for Midi (Mega Pin16 Tx2)

And here is an example of what is required to drive it

void midi_note_on(byte channel, byte pitch, byte velocity) {
  Serial2.write(0x90 | (channel & 0x0F));
  Serial2.write(pitch);
  Serial2.write(velocity);
}
void midi_note_off(byte channel, byte pitch, byte velocity) {
  Serial2.write(0x80 | (channel & 0x0F));
  Serial2.write(pitch);
  Serial2.write(velocity);
}

I hope this helps....

Rob