Go Down

Topic: Getting incorrect MIDI signals (Read 848 times) previous topic - next topic

tinker_about

I've created a pedal board using this schematic (apart from the analog inputs):



The code for the project is below. The switching part works fine, midi is send when a switch is clicked. The problem is when I monitor the results using Midi Monitor instead of getting different notes on the same channel I get the same note on different channels instead. Also about half of the time I get 2-3 messages from a single switch.

This is me cycling through each of the eight switches, note the duplicates:

Code: [Select]

15:09:51.543 From MIDI Port Note On 8 G8 1
15:09:53.496 From MIDI Port Note On 9 G8 1
15:09:53.497 From MIDI Port Note On 9 G8 1
15:09:54.238 From MIDI Port Note On 10 G8 1
15:09:54.239 From MIDI Port Note On 10 G8 1
15:09:54.997 From MIDI Port Note On 11 G8 1
15:09:54.998 From MIDI Port Note On 11 G8 1
15:09:55.785 From MIDI Port Note On 12 G8 1
15:09:57.628 From MIDI Port Note On 13 G8 1
15:09:58.412 From MIDI Port Note On 14 G8 1
15:09:59.177 From MIDI Port Note On 15 G8 1



Code: [Select]


#include "Midi.h"

// MIDI Class
Midi midi(Serial);

int lastRead[8];

void setup()
{
  // Configure digital pins for input.
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);
  pinMode(8, INPUT);
  pinMode(9, INPUT);
 
  midi.begin(0);
 
  // Grap the current on / off switch state
  for (int i=0; i <= 7; i++){

    lastRead[i] = digitalRead(2+i);
  }

 
}

// MIDI channel to send messages to
int channelOut = 1;
int baseNote = 40;
int velocity = 127;

void doKeys()
{

  for (int i = 0; i<= 7; i++) {
   
   // check to see if a switch state as changed, if so output a note and set the current state
   
   if (lastRead[i] != digitalRead(2+i)) {
     midi.sendNoteOn(baseNote+i,velocity,channelOut);
     lastRead[i] = digitalRead(2+i);
   }
  }

}


void loop()
{
  doKeys();
}



Any Ideas?

tinker_about

Updated the Midi library and Arduino, threw in some delays and now it is working like a champ.

Code: [Select]

#include <MIDI.h>


int lastRead[8];

void setup()
{
  // Configure digital pins for input.
  pinMode(2, INPUT);
  pinMode(3, INPUT);
  pinMode(4, INPUT);
  pinMode(5, INPUT);
  pinMode(6, INPUT);
  pinMode(7, INPUT);
  pinMode(8, INPUT);
  pinMode(9, INPUT);
 
  MIDI.begin(0);
 
  // Grap the current on / off switch state
  for (int i=0; i <= 7; i++){

    lastRead[i] = digitalRead(2+i);
  }

 
}

// MIDI channel to send messages to
int channelOut = 1;
int baseNote = 40;
int velocity = 127;

void doKeys()
{

  for (int i = 0; i<= 7; i++) {
   
   // check to see if a switch state as changed, if so output a note and set the current state
   
   if (lastRead[i] != digitalRead(2+i)) {
     MIDI.sendNoteOn(baseNote+i,velocity,channelOut);
     lastRead[i] = digitalRead(2+i);
   }
   
   delay(1);
  }

}


void loop()
{
  doKeys();
  delay(10);
}

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