Go Down

Topic: switch matrix polyphony (Read 529 times) previous topic - next topic

MEOW

hey. im stuck.

im trying to make a midi controller with added features of tanspose functions with led interfacing, which all works fine

but im struggling in finding a way of making it so i can read more than 1 switch at a time without getting phantom notes playing?

i have put pull down resistors in with each switch and a diode. what would you say id do?

ive made this code from a mixture of things ive found on the forum

int HotPin[6] = {2,3,4,5,6,7}; //Hot (output) pins                                             //
int GndPin[6] = {14,15,16,17,18,19}; //Ground (input) pins                                             //
int OldKeyPress[36] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};           //
int NewKeyPress[36] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};           //
int KeyNum = 1; //Identifies the key being read                                                  //
int MidiNote = 60; //The MIDI note to be played (Middle C is 60)
int midnote = 56; // the midi note automatically transposed to
int val = 0;// to store state of transpose button up
int val1 = 0;// to store state of transpose button down
int state = 0;

void setup()                                                                                   
{                                                                                               
Serial.begin(31250);
    pinMode(2, OUTPUT); 
    pinMode(3, OUTPUT);
    pinMode(4, OUTPUT);
    pinMode(5, OUTPUT);
    pinMode(6, OUTPUT);
    pinMode(7, OUTPUT);
    pinMode(8, INPUT); //transpose up
    pinMode(9, INPUT); //transpose down
    pinMode(10, OUTPUT); //leg one of bipolar LED 1
    pinMode(11, OUTPUT); // leg two of bipolar LED 1
    pinMode(12, OUTPUT); // leg one of bipolar LED 2
    pinMode(13, OUTPUT); // leg two of bipolar LED 2
    pinMode(14, INPUT);
    pinMode(15, INPUT);
    pinMode(16, INPUT);
    pinMode(17, INPUT);
    pinMode(18, INPUT);
    pinMode(19, INPUT);
   
   
    digitalWrite (10, HIGH);
    digitalWrite (11, LOW);
    delay (100);
    digitalWrite (10, LOW);
    digitalWrite (11, HIGH);
    delay (100);
    digitalWrite (10, HIGH);
    digitalWrite (11, LOW);
    digitalWrite (12, LOW);
    digitalWrite (13, HIGH);
    delay (100);
    digitalWrite (10, LOW);
    digitalWrite (11, LOW);
    digitalWrite (12, HIGH);
    digitalWrite (13, LOW);
    delay (100);
    digitalWrite (12, LOW);
    digitalWrite (13, HIGH);
    delay (100);
    digitalWrite (12, LOW);
    digitalWrite (13, LOW);
   
}

void loop()                                                                                     


  for (int h=0; h <= 5; h++)                                                                   
  {                                                                                             
    digitalWrite(HotPin[h], HIGH);                                                             
    {                                                                                           
      for (int g=0; g <=5; g++)                                                               
      {                                                                                       
        KeyNum = (g * 6) + h; //Sets KeyNum to a value from 0 to 31 (C1 is 04)
        if(analogRead(GndPin[g]) >= 600)
       {
          NewKeyPress[KeyNum] = 1;
        }
        else
        {
          NewKeyPress[KeyNum] = 0;
        }
        //Find out if the key if pressed         
        MidiNote = KeyNum + midnote; //Makes C1 on the keyboard middle C                             
        if (NewKeyPress[KeyNum] == 1 && OldKeyPress[KeyNum] == 0) //If key is pressed         
        {                                                                                     
          MidiMessage(0x90, MidiNote, 0x70); //note on, channel 1                             
        }                                                                                       
        else if (NewKeyPress[KeyNum] == 0 && OldKeyPress[KeyNum] == 1) //If key is released     
        {                                                                                       
          MidiMessage(0x80, MidiNote, 0x70); //note off, channel 1                             
        }                                                                                       
        OldKeyPress[KeyNum] = NewKeyPress[KeyNum]; //Set state for next check                   
      }                                                                                         
    }
    digitalWrite(HotPin[h], LOW);                                                                                           
  }


{   
 
val = digitalRead(8) ; //reads button value
if (val == HIGH) {
midnote = 1 + midnote;
state = state + 1;
delay (250);}

val1 = digitalRead(9) ; //reads button value
if (val1 == HIGH) {
midnote = midnote - 1;
state = state - 1;
delay (250);
}


if (state == 0) {
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);}
 
  if (state == 1) {
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);}
 
  if (state == 2) {
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);}
 
  if (state == 3) {
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  }
 
  if (state == 4) {
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  }
 
  if (state == 5) {
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  }
 
  if (state == 6) {
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  }
 
  if (state == 7) {
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  }
 
  if (state == 8) {
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  }
 
  if (state == 9) {
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  }
 
  if (state == 10) {
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  }
 
  if (state == 11) {
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  digitalWrite(12, LOW);
  digitalWrite(13, LOW);
  }
 
  if (state == 12) {
  digitalWrite(10, LOW);
  digitalWrite(11, HIGH);
  digitalWrite(12, LOW);
  digitalWrite(13,HIGH);
  }
 
 
   if (state == -1) {
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);}
 
  if (state == -2) {
  digitalWrite(12, LOW);
  digitalWrite(13, HIGH);}
 
  if (state == -3) {
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);
  }
 
  if (state == -4) {
  digitalWrite(12, LOW);
  digitalWrite(13, HIGH);
  }
 
  if (state == -5) {
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);
  }
   if (state == -6) {
  digitalWrite(12, LOW);
  digitalWrite(13, HIGH);
  }
 
  if (state == -7) {
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);
  }
  if (state == -8) {
  digitalWrite(12, LOW);
  digitalWrite(13, HIGH);
  }
 
  if (state == -9) {
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);
  }
  if (state == -10) {
  digitalWrite(12, LOW);
  digitalWrite(13, HIGH);
  }
 
  if (state == -11) {
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);
  digitalWrite(10, LOW);
  digitalWrite(11, LOW);
  }
   if (state == -12) {
  digitalWrite(12, HIGH);
  digitalWrite(13, LOW);
  digitalWrite(10, HIGH);
  digitalWrite(11, LOW);
  }
}
}

                                                                                           
//=================================================================================================
void MidiMessage(char cmd, char data1, char data2)                                               //
{                                                                                                //
  Serial.print(cmd, BYTE);                                                                       //
  Serial.print(data1, BYTE);                                                                     //
  Serial.print(data2, BYTE);                                                                     //
}                                                                                                //
//=================================================================================================
 



any help would be much appreciated!

thanks

sam

Go Up
 


Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

Arduino
via Egeo 16
Torino, 10131
Italy