Pages: [1]   Go Down
Author Topic: Seeking guidance: Read 2 8 channel Multiplexers/send midi  (Read 1261 times)
0 Members and 1 Guest are viewing this topic.
New York City, NY
Offline Offline
Full Member
***
Karma: 0
Posts: 101
Arduino Rocks!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello all,
 a little background, I am trying to build a midi percussion instrument useing piezo sensors  [that expands upon Todbot's mididrumkit http://todbot.com/arduino/sketches/midi_drum_kit/ by employing the Fluidforms Cassius punching bag's http://www.arduino.cc/playground/Projects/ArduinoUsers&sa=U&ei=EHeoTZ_5JMK60QHBnv35CA&ved=0CBQQFjAC&sig2=dRV4dGbMY9LtUx7ylfMGGw&usg=AFQjCNEa5PVsvBFmui1eRMli_iT241942g code, another geat project that was very helpfull is the midifootstep http://www.thebox.myzen.co.uk/Hardware/MIDI_Footsteps.html and less I forget my homies at ITP Physical Computing http://itp.nyu.edu/physcomp/]. In my draft below sensorID are notes middle C and up one and one half octaves, where value [j] is the velocity byte i.e. the last byte of the  'note on'/'note off' command to be sent. I haven't tested the sketch yet. I could really use a little guidance as the syntax is still very new to me. I may have overlooked or left something out so if I've made an error or you see a way I can build/optimise a working sketch your insight would be greatly appreciated.  
Code:
/* ReadMultiplexedSensorsAndSendMIDI
 *
 * Reads 2 8 channel Multiplexers and sends midi note and velocity values
 *
 *
 */
#define CONTROLpin1 2
#define CONTROLpin2 3
#define CONTROLpin3 4
#define PIEZOTHRESHOLD 100
#define mux1 0
#define mux2 1
#define drumchan 1
// Variables:
char sensorValueToSend = 0;            // Value of the sensor
int actualSensorValue = 0;             // value from the analog input
int val,t;
char sensorID[16] = { 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74};// middle C = 60
//int currentState[60]; // current state of sensors
//int lastState[60];    // the last state of the sensors
// Some error chacking would be good here.
//If the values exceede 128 the will not fit in one byte.
// Send a MIDI note-on message.  Like pressing a piano key
void noteOn(byte channel, byte sonsorID, byte value) {
  midiMsg( (0x90 | channel), sensorID, value);
}

// Send a MIDI note-off message.  Like releasing a piano key
void noteOff(byte channel, byte sensorID, byte value) {
  midiMsg( (0x80 | channel), note, velocity);
}

// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
  digitalWrite(ledPin,HIGH);  // indicate we're sending MIDI data
  Serial.print(cmd, BYTE);
  Serial.print(data1, BYTE);
  Serial.print(data2, BYTE);
  digitalWrite(ledPin,LOW);
}
void setup() {
  //  set the states of the I/O pins:
  pinMode(LEDpin, OUTPUT);
  pinMode(CONTROLpin3, OUTPUT);
  pinMode(CONTROLpin2, OUTPUT);
  pinMode(CONTROLpin1, OUTPUT);
  begin.Serial(31250);
}
void loop() {
  int i;
  int j;
  for (i=0; i <8; i++) {
   // set control pins on the multiplexers
    digitalWrite(CONTROLpin3, (i&4)>>2);//bit3
    digitalWrite(CONTROLpin2, (i&2)>>1);//bit2
    digitalWrite(CONTROLpin1, (i&1)   );//bit1
    // read the analogue inputs and send the values of the sensors.
    for(j=0; j<2; j++){
      val = analogRead(mux1); //  the "#define mux1" type statements are ok for mapping Mux to analog port
// Serial.print(mux1); //use the result  << only need for debug
if( val >= PIEZOTHRESHOLD ) {
t=0;
// this while mini-loop reads over & over waiting for the signal to die down?
// keep conversion time in mind again
while(analogRead(mux1) >= PIEZOTHRESHOLD/2) {
t++;
}
noteOn(0x90 | channel,note, t*2); // replace note with array[i,j]
delay(t);
noteOff(0x80 | channel,note,0);
}
val = analogRead(mux2);
// Serial.print(mux2); //use the result  << only need for debug
if( val >= PIEZOTHRESHOLD ) {
t=0;
// this while mini-loop reads over & over waiting for the signal to die down?
// keep conversion time in mind again
while(analogRead(mux2) >= PIEZOTHRESHOLD/2) {
t++;
}
noteOn(0x90 | channel,note, t*2); // replace note with array[i,j]
delay(t);
noteOff(0x80 | channel,note,0);
}

    }
    // if you uncomment this line you can check the control pins
    // of the multiplexers with your multimeter.
    //delay(500);
  }

}



Am I on the right track here, and can anyone help with
Quote
// replace note with array[i,j]
==========


=============
http://seanhannity.com
http://barakobama2011.com
Loved hearing from the Arduino people on  The Flossweekly podcast on the TWiT network http://twit.tv/floss61
===========
Thank you in advance
Caesar
« Last Edit: April 21, 2011, 04:25:19 pm by Pitchoilcan » Logged

================================
http://twit.tv/floss61
Think different
Think UbuntuStudio
============================

Pages: [1]   Go Up
Jump to: