I am in need of some help with this sketch.
I have a drum module kit that is hooked up to a Yamaha DTX drum trigger module. The drum trigger module was originally hooked up to a MIDI-tron decoder board that was sending signals to a boarduino. The boarduino is either triggering digital outputs to physical intruments or triggering analog outputs that are going to an amp and speaker that are playing sounds that are programmed through the synthesizer.
The MIDI-tron decoder board is now discontinued so I was trying to use the sparkfun MIDI shield to interpret the MIDI signal coming from the Yamaha DTX500 drum trigger module and then triggering either analog or digital pins (playing the instruments). So I just need to incorporate a MIDI decoder on a sketch I had originally. MIDI is new to me so any help or input would be helpful
The sketch below was the original, I did post it several weeks ago without any comments. I have now added the comments to the sketch so hopefully this will help. Also, I will attach a sketch with with my attempt to add a decoder to the original sketch through my research (not as confident with this one)
In a general sense, each of the segments of the MIDI Sound Studio is behaving in a similar way: Each station has a synthesizer/MIDI signal handler which either plays sounds through a speaker, or passes MIDI signals on to the attached MIDI decoder board. The Miditron MIDI decoder board on each section receives MIDI messages from the synthesizer/MIDI adapter, and processes these signals. The board then turns on or off outputs based on these signals; these outputs are connected to the gate of a FET on the FET boards (FET = Field Effect Transistor: a transistor that uses an electric field to control the shape and hence the conductivity of a channel of one type of charge carrier in a semiconductor material). When the FET board is activated, the source pin grounds to the drain. Each of the acutators for the instruments on the wall (ie motors, solenoids, etc) is attached to the source pin of one of the FETs, and when the FET is activated, the actuator “plays” the instrument. In summary: 1) The MIDI signal is generated by either a computer (Patcher and Sequencer) or trigger module (drums):
-
The MIDI signal is passed to the synthesizer (synthesizer is integrated into the USB-MIDI interface for the Patcher and Sequencer, and is part of the Drum Trigger Module for the drums):
-
The synthesizer generates sound based on the MIDI signal (which is either ignored, or sent to the speaker) and passes the MIDI message out to the Miditron MIDI decoder board, which is connected by a MIDI cable to the synthesizer:
-
The MIDI decoder board interprets the MIDI message. The message consists of channel, note, and velocity information; if the message matches the channel and note number of one of its outputs, the output is turned on or off, depending on the message velocity.
-
When a decoder board output is activated (set to an output of 5V), the 5V signal is applied to the “gate” of an N-channel FET (Field Effect Transistor). When the gate of the FET is high, it allows the FET to conduct, and provides a ground path for whatever is connected to the “source” of the FET.
-
Concurrently, the actuator (motor, solenoid) for every instrument on the wall is connected to the high side of a power supply continuously, and the low side of the actuator is connected to the “source” of the FET; when the FET activates, it provides a ground path to the actuator, and the actuator can “play” the instrument.
//set gate time for each device in milliseconds
int crash=15;
int snare=20;
int smalltom=20; //Durations for each motor to be activated/turned on
int largetom=20;
int cowbell=20;
int gatetime [5] = {crash,snare,smalltom,largetom,cowbell}; //Array that stores gate times for each instrument
unsigned long timenow [5];//Array that stores the current duration for each note, see below for more
void setup() //Assigns appropriate roles to pins
{
for (int i=8;i<15;i++)//pins 8-14
{
pinMode(i, OUTPUT);//pins 8-14 are outputs
}
for (int i=2;i<8;i++)//2-7 inputs from MIDI decoder board
{
pinMode (i, INPUT); //pin 2-7 are inputs
}
}
void loop()//Pin 7 determines what type of action if it is high- synth, low = actual instrument
{
if (digitalRead(7)==LOW)//inputs low = analog (synth music)
{
digitalWrite(14, HIGH);//pin 14 is on (enables power to the speaker relay, turns speaker on)
for (int i=0; i<5; i++)//pins 8 to 12 low loop
{
digitalWrite(i+8,LOW);//digital outputs low (turns of actual instruments)
}
}
else //this means pin 7 is HIGH - actual instruments to be played
{
digitalWrite (14, LOW);//analog speaker relay power off, no synth music
for (int i=0;i<5;i++)//loops through all the input pins for actual instruments
{
if (digitalRead(i+2)==HIGH)//tests if the current pin is HIGH, if so... go below
{
timenow[i]=millis();//The slot in timenow gets the current program lifetime
digitalWrite(i+8, HIGH);//write HIGH to the corresponding output pin for actual drum that matches the input pin
}
if (millis() > timenow[i]+gatetime[i])//if the current program lifetime is greater than how long the instrument should be playing plus when it started playing, then go on...
{
digitalWrite (i+8,LOW);//turn the instrument off...this means the motor has been playing for long enough (gatetime for the drum)
}
}
}
}
Attached is the sketch with the MIDI decoder information as well as a block diagram. This what I need the most ammount of help with. Also I should note that I am changing the MIDI-tron decoder board to the spark fun MIDI shield. So a little bit of the wiring will change
MIDI_drums_original_with_serial_and_comments.ino (3.4 KB)
MIDI Repeater Board.pdf (28.7 KB)
Drum Instrument Wiring.pdf (27.3 KB)
Drums Equip Block Diagram.pdf (16 KB)