Show Posts
Pages: [1] 2
1  Using Arduino / Audio / Re: MIDI Note On/Off Messages on: April 29, 2013, 01:47:32 am
I'm also having trouble now where some of the button send out a MIDI Note On message at the same pitch, but I'm not sure what it could be. Perhaps my circuit is a little dodgy or something?
2  Using Arduino / Audio / Re: MIDI Note On/Off Messages on: April 28, 2013, 01:53:15 pm
Hiya,

Yes it worked! Thank you smiley

The extra variables are for the additional buttons. Essentially copied the code for 9 buttons. I'm not sure what you mean by arrays though?
3  Using Arduino / Audio / Re: MIDI Note On/Off Messages on: April 27, 2013, 05:40:33 am
Thanks for your reply:)

Instead, you should be looking for a change of state (on to off, or off to on). For each button, save the state. When reading the state, compare it to the value last time the loop and only send a MIDI message if the value has changed. Then set the saved state to the current reading.

Okay, so by using the buttonState function, does this code make a little more sense?
Code:


// this constant won't change:
const int  buttonPin = 2;    // the pin that the pushbutton is attached to
const int ledPin = 13;       // the pin that the LED is attached to

// Variables will change:
int buttonState = 0;         // current state of the button
int lastButtonState = 0;     // previous state of the button

void setup() {
  // initialize the button pin as a input:
  pinMode(buttonPin, INPUT);
  // initialize the LED as an output:
  pinMode(ledPin, OUTPUT);
}


void loop() {
  // read the pushbutton input pin:
  buttonState = digitalRead(buttonPin);

  // compare the buttonState to its previous state:
  if (buttonState != lastButtonState) {
 
    if (buttonState == HIGH) {
      // if the current state is HIGH then the button went from off to on:
    MIDI.sendNoteOn(36, 127, 1);
   
    }
    else {
      // if the current state is LOW then the button went from on to off:
    MIDI.sendNoteOff(36, 0, 1); 
  }
  }
  // save the current state as the last state,
  //for next time through the loop
  lastButtonState = buttonState;
 
}

//  plays a MIDI note.  Doesn't check to see that

void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}
4  Using Arduino / Audio / MIDI Note On/Off Messages on: April 27, 2013, 04:58:56 am
Hey all,

I have built a MIDI controller, consisting of a 3x3 grid of arcade buttons, 4 pots and 2 faders. The pots and faders are attached to the analog pins on an Arduino Uno and send MIDI CC Messages. The 3x3 grid buttons are attached to the digital pins and send Note On messages when pushed and Note Off messages otherwise.

The problem with the buttons is that they continually send MIDI Note Off messages when they are not pressed. This causes the computer that the controller is attached to to slow down alot and causes lag. It's just not really ideal. Is there a way to code the Arduino so that it only sends a Note On message and then only one Note Off message when the button is let go?

The code I am using is below.

Thanks  smiley


Code:
#include <MIDI.h>


//**BUTTONS**
// Set inputs and outputs 
const int BUTTON1 = 2;
const int BUTTON2 = 3;
const int BUTTON3 = 4;
const int BUTTON4 = 5;
const int BUTTON5 = 6;
const int BUTTON6 = 7;
const int BUTTON7 = 8;
const int BUTTON8 = 9;
const int BUTTON9 = 10;
const int LED = 13;
int buttonState = 0;


void setup() { 
  //  Set MIDI baud rate:
  Serial.begin(31250);   

//**BUTTONS**
  pinMode(BUTTON1, INPUT);
  pinMode(BUTTON2, INPUT);
  pinMode(BUTTON3, INPUT);
  pinMode(BUTTON4, INPUT);
  pinMode(BUTTON5, INPUT);
  pinMode(BUTTON6, INPUT);
  pinMode(BUTTON7, INPUT);
  pinMode(BUTTON8, INPUT);
  pinMode(BUTTON9, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
   // read the pushbutton value:
  buttonState = digitalRead(BUTTON1);
 
  //check if the button has been pressed.
  //if the button state is HIGH, turn on the LED and play a note:
  if (buttonState == HIGH) {
    digitalWrite(LED, HIGH);
    MIDI.sendNoteOn(36, 127, 1);
  }
  else {
    digitalWrite(LED, LOW);
    MIDI.sendNoteOff(36, 0, 1);
  }
}


//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}
5  Using Arduino / Audio / Re: Arcade Button MIDI Controller on: March 19, 2013, 07:06:44 pm
Thanks for your input guys smiley

Code:
#include <MIDI.h>


// POT Variables:
int input_nb = 6;                               // number of analog inputs
int AV[6] = {0,0,0,0,0,0};                      // define variables for the controller data
byte LastAV[6] = {0,0,0,0,0,0};                 // define the last value variables
byte midiCCselect[6] = {20,21,22,23,24,25};     // MIDI controller number (20-31 undefined) this is good for adding extra inputs later on.
byte thresh[6] = {1,1,1,1,1,1};                 // select threshold for each analog input



void setup() {
 
  //**BUTTONS**
  // Set inputs and outputs 
  int BUTTON1 = 2;
  int BUTTON2 = 3;
  int BUTTON3 = 4;
  int BUTTON4 = 5;
  int BUTTON6 = 6;
  int BUTTON7 = 7;
  int BUTTON8 = 8;
  int BUTTON9 = 9;
  int LED = 13;
 
  //  Set MIDI baud rate:
  Serial.begin(31250);   

  pinMode(BUTTON1, INPUT);
  pinMode(BUTTON2, INPUT);
  pinMode(BUTTON3, INPUT);
  pinMode(BUTTON4, INPUT);
  pinMode(BUTTON5, INPUT);
  pinMode(BUTTON6, INPUT);
  pinMode(BUTTON7, INPUT);
  pinMode(BUTTON8, INPUT);
  pinMode(BUTTON9, INPUT);
  pinMode(LED, OUTPUT);
}

void loop() {
 
  //**POTS**
 
  for (int x =0; x < input_nb; x++) {     // initialisation; condition; increment   
 
  //  Pot value = 1023
  AV[x] = analogRead(x);
 
  // Divide this value so it equals 127 (for MIDI)
  int cc = AV[x]/8;
 
  // If the Control Change is not equal to the last analog value, then send a MIDI CC:
  if (cc !=LastAV[x]) {
   
  //MIDI Control Change
  midiCC(0xB0, midiCCselect[x], cc);
 
   // The last value read becomes the new value for the next if statement:
  LastAV[x] = cc;
    }
  }
   
   
   
  // **BUTTONS**
  {
  // read input pins (CURRENTLY ONE BUTTON ONLY FOR TESTING PURPOSES)
  buttonState = digitalRead(BUTTON1);
 
  //check if the button has been pressed.
  //if pressed, the buttonState is LOW:
  if (digitalRead(BUTTON1) == LOW && previousState == LOW)
  digitalWrite(LED, LOW);
  MIDI.sendNoteOn(36,127,1);    //Send Note (C2, vel.127, ch.1)
  note = 1;
  }
  else{
    digitalWrite(LED,HIGH);    //button not pressed, turn off LED
    if(note){
      MIDI.sendNoteOff(36,0,1);
      note = 0;
    }
  }

 

// **POTS** sends a Midi CC.
void midiCC(byte CC_data, byte c_num, byte c_val){
  Serial.write((byte)CC_data);
  Serial.write((byte)c_num);
  Serial.write((byte)c_val);
}

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}







I've adapted my code to add what has been suggested. I've initialised digital pins for later use, but a button will only be added to one pin for testing purposes.

Does this newer code seem more hopeful?
6  Using Arduino / Audio / Re: Arcade Button MIDI Controller on: March 18, 2013, 08:03:42 am
Thank you smiley The type of button I'm using however is not a switch. It returns to its original position once it has been pressed. Will the code you have suggested still be valid for this type of button?
7  Using Arduino / Audio / Re: Arcade Button MIDI Controller on: March 17, 2013, 12:55:17 pm
Code:
// POT Variables:
int input_nb = 6;                               // number of analog inputs
int AV[6] = {0,0,0,0,0,0};                      // define variables for the controller data
byte LastAV[6] = {0,0,0,0,0,0};                 // define the last value variables
byte midiCCselect[6] = {20,21,22,23,24,25};     // MIDI controller number (20-31 undefined) this is good for adding extra inputs later on.
byte thresh[6] = {1,1,1,1,1,1};                 // select threshold for each analog input

// BUTTON Variables:
const int buttonPin = 2;     // the number of the pushbutton pin
const int ledPin =  13;      // the number of the LED pin
int buttonState = 0;         // variable for reading the pushbutton status
byte note = 0;

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250); // 31250
 
 
  //**BUTTONS**
  // initialize the LED pin as an output:
  pinMode(ledPin, OUTPUT);     
  // initialize the pushbutton pin as an input:
  pinMode(buttonPin, INPUT);   
}

void loop() {
 
  //**POTS**
 
  for (int x =0; x < input_nb; x++) {     // initialisation; condition; increment           
  //  Pot value = 1023
  AV[x] = analogRead(x);
  // Divide this value so it equals 127 (for MIDI)
  int cc = AV[x]/8;
  // If the Control Change is not equal to the last analog value, then send a MIDI CC:
  if (cc !=LastAV[x]) {
  //MIDI Control Change
  midiCC(0xB0, midiCCselect[x], cc);
   // The last value read becomes the new value for the next if statement:
  LastAV[x] = cc;
    }
   
   
  // **BUTTONS**
 
  // read the state of the pushbutton value:
  buttonState = digitalRead(buttonPin);

  // check if the pushbutton is pressed.
  // if it is, the buttonState is LOW:
  if (buttonState == HIGH) {     
  // Play a MIDI note:   
    noteOn(0x90, note, 0x40); 
  }
  else {
  // Note OFF??:
    digitalWrite(ledPin, LOW);
  }

  } 
}

// **POTS** sends a Midi CC.
void midiCC(byte CC_data, byte c_num, byte c_val){
  Serial.write((byte)CC_data);
  Serial.write((byte)c_num);
  Serial.write((byte)c_val);
}

// *BUTTONS**

//  plays a MIDI note.  Doesn't check to see that
//  cmd is greater than 127, or that data values are  less than 127:
void noteOn(int cmd, int pitch, int velocity) {
  Serial.write(cmd);
  Serial.write(pitch);
  Serial.write(velocity);
}






This is my code so far (it is a bit of a mess, I apologise!)
8  Using Arduino / Audio / Re: Arcade Button MIDI Controller on: March 17, 2013, 12:53:50 pm
Thank you smiley

Code wise, how do I go about triggering a note on message?

I'm thinking it must be an if statement - so if the button state is high, a note plays? Not sure how to write this though.
9  Using Arduino / Audio / Arcade Button MIDI Controller on: March 17, 2013, 09:54:22 am
Hey everyone,

I'm in the process of building a MIDI controller using the Arduino Uno. So far, I have successfully wired six pots and written a code that makes use of MIDI Control Change messages, to control parameters within a Digital Audio Workstation.

My next step is to add arcade buttons that trigger Note On/Off messages. I have so far wired up one button so that its "NO" terminal plugs into digital pin 12, (TX is being used to wire the MIDI output) and the common terminal is wired to the ground.

I am not sure if this is right so far, or what my next stage is.

Any help would be great smiley
10  Using Arduino / Audio / Re: MIDI Controller - Potentiometer Eratic/No Data on: March 06, 2013, 10:40:17 am
Thanks for the reply. I have tried this but still no luck. The first pot (controller number 20) works but the second pot does not. Any other ideas? smiley-sad
11  Using Arduino / Audio / MIDI Controller - Potentiometer Eratic/No Data on: March 05, 2013, 12:26:21 pm
Hi everyone,

I am currently building a MIDI controller using the Arduino Uno.

I wrote a code using MIDI Control Change messages to allow one pot to be assigned to a parameter within a Digital Audio Workstation. This has worked great.

I have now tried to extend this code to add another pot. The pot either gives eratic data or does not respond at all.

I have posted copies of both my code and the circuit layout (I'm pretty new to both these things, so please forgive me if they are not brilliant!)

I have searched this forum for previous topics and come across some help, but I'm still extremely stuck.


Code:
// Variables:
int input_nb = 2;                       // number of analog inputs
int AV[2] = {0,0};                      // define variables for the controller data
byte LastAV[2] = {0,0};                 // define the last value variables
byte midiCCselect[2] = {20,21};         // MIDI controller number (20-31 undefined) this is good for adding extra inputs later on.
byte thresh[2] = {1,1};                 // select threshold for each analog input

void setup() {
  //  Set MIDI baud rate:
  Serial.begin(31250); // 31250
}

void loop() {
  for (int x =0; x < input_nb; x++) {     // initialisation; condition; increment           

    //  Pot value = 1023
    AV[x] = analogRead(x);

    // Divide this value so it equals 127 (for MIDI)
    int cc = AV[x]/8;

    // If the Control Change is not equal to the last analog value, then send a MIDI CC:
    if ( abs(cc !=LastAV[x]) {

      //MIDI Control Change
      midiCC(0xB0, midiCCselect[x], cc);

      // The last value read becomes the new value for the next if statement:
      LastAV[x] = cc;
    }

  } 
}

// sends a Midi CC.
void midiCC(byte CC_data, byte c_num, byte c_val){
  Serial.write((byte)CC_data);
  Serial.write((byte)c_num);
  Serial.write((byte)c_val);
}




Any help would be appreciated.
12  Using Arduino / Audio / Re: VERY Basic MIDI Controller Help on: January 30, 2013, 01:07:00 pm
Hi all,

Firstly thank you for your previous help. My Arduino now plays MIDI notes straight into Pro Tools and I'm getting to grips with changing the code so that I can change the velocity, length of the notes and the min/max pitch.

The next thing I'd like to do is add a potentiometer so I can begin to control parameters in my DAW. What would be my first steps? I want to be able to go into the DAW and select a parameter for the potentiometer to effect.

Thank you smiley
13  Using Arduino / Audio / Re: VERY Basic MIDI Controller Help on: January 18, 2013, 02:33:42 am
My computer picks up the cable.

Okay I shall adapt my circuit so it has the same circuit output as the one you have suggested and post my results. Thanks!
14  Using Arduino / Audio / Re: VERY Basic MIDI Controller Help on: January 17, 2013, 02:15:18 pm
Oh I see. I have used the circuit from the link. I was using a MIDI to USB cable which was connected to the MIDI output on the circuit. What makes it a bad circuit?
15  Using Arduino / Audio / Re: VERY Basic MIDI Controller Help on: January 16, 2013, 06:39:29 pm
The Arduino is not being detected by my computer as a controller sending MIDI information.
Pages: [1] 2